This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Add two methods to handle the notification. You want to create and add a new store when the old one has been removed. | |
- (void) didChangePersistentStores:(id)notification { | |
NSArray *addedStores = nil; | |
NSArray *removedStores = nil; | |
NSArray *uuidChangedStores = nil; | |
addedStores = [[notification userInfo] valueForKey:NSAddedPersistentStoresKey]; | |
removedStores = [[notification userInfo] valueForKey:NSRemovedPersistentStoresKey]; | |
uuidChangedStores = [[notification userInfo] valueForKey:NSUUIDChangedPersistentStoresKey]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) recursiveSave:(NSManagedObjectContext *)context { | |
NSError *error = nil; | |
[context performBlock:{ | |
if (![context save:&error]){ | |
[self errorHandler:error]; | |
} else { | |
[self recursiveSave:[context parentContext]]; | |
} | |
}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the initializer, or viewWillAppear,etc: | |
[self addObserver:self forKeyPath:keyPath options:options context:(__bridge void*)self]; | |
// in dealloc, or viewDidDisappear, etc: | |
[self removeObserver:self forKeyPath:keyPath context:(__bridge void*)self]; | |
- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context { | |
if ((__bridge id)context == self){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; | |
[context setParentContext:someOtherContext]; | |
result = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { | |
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ | |
[[self tableView] endUpdates]; | |
}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSManagedObject *someObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; | |
value = [someObject lastName]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSManagedObject *someObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; | |
[[someObject managedObjectContext] performBlock:^{ | |
value = [someObject lastName]; | |
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSManagedObject *row = [[self fetchedResultsController] objectAtIndexPath:indexPath]; | |
[[row managedObjectContext] performBlock:^{ | |
NSString *text = nil; | |
// Fire a fault. | |
text = [row lastName]; | |
// Update the user interface with the value. | |
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
NSManagedObjectContext *rootContext = nil; | |
// Override point for customization after application launch. | |
// 1. Create an NSManagedObjectContext with private queue concurrency | |
rootContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; | |
// 2. Instantiate a concrete NSPersistentStore by adding it to the coordinator asynchronously. | |
[rootContext performBlock:^{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In your answer, you have this: | |
NSManagedObjectID *objectID = [person objectID]; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
//update your UI here | |
Person *thePerson = (Person *)[[delegate managedObjectContext] objectWithID:objectID]; | |
self.myUIElement.text = person.firstname; |
OlderNewer