NSOperation and waitUntilFinished
NSOperation and waitUntilFinished
- Subject: NSOperation and waitUntilFinished
- From: Koen van der Drift <email@hidden>
- Date: Sat, 20 Oct 2012 12:42:29 -0400
I am trying to understand how to wait for an NSOperation to complete, for example:
NSOperationQueue *opQueue = [[NSOperationQueue alloc] init];
ImportOperation *importOp = [[ImportOperation alloc] initWithArray: anArray];
NSLog@"start import");
[opQueue waitUntilAllOperationsAreFinished];
[opQueue addOperation: importOp];
NSLog(@"end import");
And in main() of the operation:
- (void)main
{
// Create context on background thread
AppDelegate *appController = [[NSApplication sharedApplication] delegate];
self.context =[[NSManagedObjectContext alloc] init];
[self.context setUndoManager:nil];
[self.context setPersistentStoreCoordinator:[appController persistentStoreCoordinator]];
// Register context with the notification center
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(mergeChanges:)
name:NSManagedObjectContextDidSaveNotification
object: self.context];
NSLog(@"begin of importRecords in operation");
[self.context importRecords: self.recordsArray]; // long process to import records from an array of dictionaries
NSLog(@"end of importRecords in operation");
}
The NSLog's appear in this order in the console:
start import
end import
begin of importRecords in operation
end of importRecords in operation
while I'd like it to be:
start import
begin of importRecords in operation
end of importRecords in operation
end import
Can anyone explain this?
Thanks,
- Koen.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden