Database Reference
In-Depth Information
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
As you can see, we added an options dictionary. We use the key
NSPersistentStoreUbiquitousContentNameKey and give it a value of Store. We then pass that options
object as the option parameter in the addPersistentStoreWithType:configuration:URL:options:
error: method. I know it may sound simple, but you have just enabled iCloud support. But we
aren't done setting up our app to handle the notifications I mentioned earlier. Let's add our self as an
observer to those by modifying the method managedObjectContext .
- (NSManagedObjectContext *)managedObjectContext
{
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(persiste
ntStoreDidImportContent:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:coordinator];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector
(persistentStoresWillChange:) name:NSPersistentStoreCoordinatorStoresWillChangeNotification
object:coordinator];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(persistent
StoresDidChange:) name:NSPersistentStoreCoordinatorStoresDidChangeNotification object:coordinator];
}
return _managedObjectContext;
}
The only lines we added here are the three notifications. We are now listening
for NSPersistentStoreDidImportUbiquitousContentChangesNotification ,
NSPersistentStoreCoordinatoreStoresWillChangeNotification , and
NSPersistentStoreCoordinatorStoresDidChangeNotification . Now we need to write the three
selectors we referenced.
#pragma mark - iCloud Core Data Notification Methods
-(void)persistentStoresWillChange:(NSNotification *)notification {
if([_managedObjectContext hasChanges]){
 
Search WWH ::




Custom Search