Skip to content

Instantly share code, notes, and snippets.

@kishikawakatsumi
Created May 20, 2012 09:32
Show Gist options
  • Save kishikawakatsumi/2757488 to your computer and use it in GitHub Desktop.
Save kishikawakatsumi/2757488 to your computer and use it in GitHub Desktop.
merge managed context in CoreData
// バックグラウンドでGoogle Calendarからイベントを受信して保存するクラス
- (void)main {
if (!self.isCancelled) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (!self.isCancelled) {
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
[managedObjectContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
SPEventStore *eventStore = [SPEventStore defaultEventStore];
events = [[eventStore searchEventsWithPredicate:predicate] retain];
}
[pool release];
if (!self.isCancelled) {
[resultsDelegate performSelectorOnMainThread:@selector(operationSearchEnded:) withObject:self waitUntilDone:NO];
}
}
}
// メインスレッドのコンテキストを管理しているクラス
- (void)anotherContextDidSave:(NSNotification *)notification {
[managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment