• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSOperation and waitUntilFinished
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSOperation and waitUntilFinished
      • From: "Gary L. Wade" <email@hidden>
  • Prev by Date: Re: Scene Kit
  • Next by Date: Re: NSOperation and waitUntilFinished
  • Previous by thread: Re: Scene Kit
  • Next by thread: Re: NSOperation and waitUntilFinished
  • Index(es):
    • Date
    • Thread