RRK

MOC

RRK
Oct 17th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void) resetApplicationModel
  2. {
  3.    
  4.     // remove the file containing the data
  5.     _managedObjectContext = nil;
  6.     _managedObjectModel = nil;
  7.     _persistentStoreCoordinator = nil;
  8.  
  9.    
  10.    
  11.     NSError *error;
  12.     NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"abc.sqlite"];
  13.    
  14.     [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
  15.            
  16.     [self managedObjectContext];
  17.    
  18.     NSMutableDictionary* userInfo = [NSMutableDictionary dictionary];
  19.     [userInfo setObject:[self managedObjectContext] forKey:@"managedObjectContext"];
  20.    
  21.     [[NSNotificationCenter defaultCenter] postNotificationName:@"kNotificationDestroyAllNSFetchedResultsControllers" object:self userInfo:userInfo];  
  22. }
  23.  
  24.  
  25. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  26. {
  27.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  28.     if (self) {
  29.  
  30.        [[NSNotificationCenter defaultCenter] addObserverForName:@"kNotificationDestroyAllNSFetchedResultsControllers" object:nil queue:nil usingBlock:^(NSNotification *note) {
  31.             NSLog(@"[%@] must destroy my nsfetchedresultscontroller", [self class]);
  32.             //m_controller = nil;
  33.             NSDictionary* userInfo = note.userInfo;
  34.             self.managedObjectContext = [userInfo objectForKey:@"managedObjectContext"];
  35.             NSLog (@"Successfully received:%@", self.managedObjectContext);
  36.        
  37.        
  38.             NSError *error;
  39.             if (![m_controller performFetch:&error]) {
  40.                 /*
  41.                  Replace this implementation with code to handle the error appropriately.
  42.        
  43.                  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.
  44.                  */
  45.                 NSLog(@"Unresolved error %@, %@", error, [error localizedDescription]);
  46.                 abort();
  47.             }          
  48.             }];    
  49.     }
  50.     return self;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment