Я хочу создать одновременно 2 операции. Он постоянно создает объект и добавляет его в очередь с интервалом 15 мс. Другая операция постоянно удаляет 1-й элемент из очереди с интервалом 10 мс.Как создать 2 операции с использованием NSOperationQueue
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
_arrInformations = [[NSMutableArray alloc] init];
queue = [NSOperationQueue new];
// start continuous processing
[NSTimer scheduledTimerWithTimeInterval:0.15
target:self
selector:@selector(addNewInformation)
userInfo:nil
repeats:YES];
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(removeInformation)
userInfo:nil
repeats:YES];
}
-(void)addNewInformation {
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(addDataWithOperation) object:nil];
/* Add the operation to the queue */
[queue addOperation:operation];
}
- (void)removeInformation {
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(removeDataWithOperation) object:nil];
/* Add the operation to the queue */
[queue addOperation:operation];
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
- (void) addDataWithOperation {
NSLog(@"Add data");
[_arrInformations addObject:@"Informations"];
}
- (void) removeDataWithOperation {
if (_arrInformations.count) {
[_arrInformations removeLastObject];
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
}
Большое спасибо!
который подходит, вы уже пробовали? – Vik
вы ссылаетесь на мой код на приведенный выше –