私は夢中になるかもしれないと思います。次のメソッドでは、別のコード行を追加しない限り、戻り値_persistentStoreCoordinatorはnilです。チェック_persistentStoreCoordinator == nil
するだけで、そうでないことを確認できます。(NSLogステートメントでもうまくいきます。)
psc
別の行を追加しない場合、ブレークポイントを使用して検査する場合は常にnil以外ですが、メソッドの最後の行で_persistentStoreCoordinatorはnilです。
最も奇妙な(またはおそらく最も役立つ?)ことは、問題が始まったときにこのクラスに変更を加えなかったことです。
どんな助けや説明も大歓迎です!
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (_persistentStoreCoordinator == nil) {
NSLog(@"SQLITE STORE PATH: %@", [self pathToLocalStore]);
NSURL *storeURL = [NSURL fileURLWithPath:[self pathToLocalStore]];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
NSError *e = nil;
if (![psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&e]) {
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:e forKey:NSUnderlyingErrorKey];
NSString *reason = @"Could not create persistent store.";
NSException *exc = [NSException exceptionWithName:NSInternalInconsistencyException
reason:reason
userInfo:userInfo];
@throw exc;
}
_persistentStoreCoordinator = psc;
if (_persistentStoreCoordinator == nil)
{
NSLog(@"We never reach here.");
}
}
return _persistentStoreCoordinator;
}