Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void) resetApplicationModel
- {
- // remove the file containing the data
- _managedObjectContext = nil;
- _managedObjectModel = nil;
- _persistentStoreCoordinator = nil;
- NSError *error;
- NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"abc.sqlite"];
- [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
- [self managedObjectContext];
- NSMutableDictionary* userInfo = [NSMutableDictionary dictionary];
- [userInfo setObject:[self managedObjectContext] forKey:@"managedObjectContext"];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kNotificationDestroyAllNSFetchedResultsControllers" object:self userInfo:userInfo];
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- [[NSNotificationCenter defaultCenter] addObserverForName:@"kNotificationDestroyAllNSFetchedResultsControllers" object:nil queue:nil usingBlock:^(NSNotification *note) {
- NSLog(@"[%@] must destroy my nsfetchedresultscontroller", [self class]);
- //m_controller = nil;
- NSDictionary* userInfo = note.userInfo;
- self.managedObjectContext = [userInfo objectForKey:@"managedObjectContext"];
- NSLog (@"Successfully received:%@", self.managedObjectContext);
- NSError *error;
- if (![m_controller performFetch:&error]) {
- /*
- Replace this implementation with code to handle the error appropriately.
- abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
- */
- NSLog(@"Unresolved error %@, %@", error, [error localizedDescription]);
- abort();
- }
- }];
- }
- return self;
- }
Advertisement
Add Comment
Please, Sign In to add comment