From time to time, my application crashes before it is fully loaded right on the following line:
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
The full method this if state is in is as follows (I think this is pretty standard):
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil) {
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreData.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __persistentStoreCoordinator;
}
Update
The failure occurs the second time the method is called -(NSPersistentStoreCoordinator *)persistentStoreCoordinator. CHANGE
frist time it is apparent from the first test monitor:
- (void)updateStats {
NSLog(@"Updating stats");
dispatch_queue_t request_queue = dispatch_queue_create("updateNumberOfSchedules", NULL);
dispatch_async(request_queue, ^{
AppDelegate *theDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];
[context setPersistentStoreCoordinator:[theDelegate persistentStoreCoordinator]];
...
});
}
The second time (when sometimes a crash occurs when my DeviceLinker class checks the database for inactive links in my checkInactiveLinks method. This method is called when launched in applicationDidBecomeActive:
-(void) checkInactiveLinks {
AppDelegate *theDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *newMoc = [[NSManagedObjectContext alloc] init];
[newMoc setPersistentStoreCoordinator:[theDelegate persistentStoreCoordinator]];
...
}
, , , , , persistentStoreCoordinator getter, __persistentStoreCoordinator ...
2
if :
-[__NSCFDictionary _hasPrecomputedKeyOrder]: unrecognized selector sent to instance 0x7dd3770
3
. -[NSPersistentStoreCoordinator unlock]: message sent to deallocated instance 0x8916090. , .