Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //appdelegate.m
- - (void) resetApplicationModel
- {
- __managedObjectContext = nil;
- __managedObjectModel = nil;
- __persistentStoreCoordinator = nil;
- // _allPageViewController.controller = nil;
- NSError *error;
- NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"abc.sqlite"];
- if ([[self.managedObjectContext persistentStoreCoordinator] removePersistentStore:[[[self.managedObjectContext persistentStoreCoordinator] persistentStores] lastObject] error:&error])
- {
- // remove the file containing the data
- if([[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error])
- {
- __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
- if([__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error] == nil)
- {
- NSLog( @"could not create new persistent store at %@ - %@", [storeURL absoluteString], [error localizedDescription]);
- }
- }
- else
- {
- NSLog( @"could not remove the store URL at %@ - %@", [storeURL absoluteString], [error localizedDescription]);
- }
- }
- else
- {
- NSLog( @"could not remove persistent store - %@", [error localizedDescription]);
- }
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kNotificationDestroyAllNSFetchedResultsControllers" object:self];
- }
- //RootViewController
- - (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;
- 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