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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com