When I login the application it seems to crash at NSManagedObjectContext *managedObjectContext = self.managedObjectContext; in the following save context method and gives the error "This NSPersistentStoreCoordinator has no persistent stores (schema mismatch or migration failure). It cannot perform a save operation.",
- (BOOL) saveContext
{
@synchronized (_localStorage) {
//NSLog(@"----------------------------Save context called---------------------------");
BOOL result = TRUE;
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil)
{
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
{
NSLog(@"----------------------------Save context failed---------------------------");
result = FALSE;
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
//NSLog(@"----------------------------Save context completed---------------------------");
return result;
}
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Badger.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES,
NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"}
};
if(![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
return __persistentStoreCoordinator;
}