On 18 Oct 2012, at 16:01, Koen van der Drift <koenvanderdr...@gmail.com> wrote:
> After some more searching I came to the following plan. > > 1. get the main context from another thread as follows: > > AppDelegate *appDelegate = [[NSApplication sharedApplication] delegate]; > NSManagedObjectContext *mainContext = [appDelegate managedObjectContext]; > > 2. use performSelectorOnMainThread to execute the fetch request: > > [mainContext performSelectorOnMainThread:@selector(executeFetchRequest:) > withObject:fetchRequest > waitUntilDone:YES]; > > However, performSelectorOnMainThread does not give a return value > back, and the selector should really be executeFetchRequest:error: > > One way to solve this would be to use an NSInvocation, I think? Or > maybe wrap the executeFetchRequest in another method, call > performSelectorOnMainThread on it, and then use a notification to send > the result back. > > Will try this later, does any of these approaches sound reasonable? Here's what you want: __block BOOL exists; dispatch_sync(dispatch_get_main_queue, ^{ NSManagedObjectContext *context = … // grab the context exists = … // query the context to see if the data already exists }); Works on OS X 10.6+ and iOS4+ _______________________________________________ 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