我有点麻烦,我创建了一个新版本的上下文并将其设为默认版本,之后我根据苹果文档更改了我的代码,现在看起来像这样:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (persistentStoreCoordinator != nil)
{
return persistentStoreCoordinator;
}
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"];
NSPersistentStoreCoordinator *psc = persistentStoreCoordinator;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
BOOL success = [psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeURL
options:options error:&error];
if (!success) {
NSLog(@"Unresolved Error");
abort();
}
return persistentStoreCoordinator;
}
但我得到一个错误,即使它是 1:1 相同的代码,在BOOL sucess
我得到一个incompatible pointer to integer conversion 'BOOL' with 'NSPersistentstore'
不知何故,映射虽然有效,但我得到了新模型,让我们说 5 次中有 4 次有效,第 5 次在该行中引发错误。
任何想法如何解决它?
更新我稍微更改了代码,现在看起来像这样
NSPersistentStore *store = [psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeURL
options:options error:&error];
if (!store) {
NSLog(@"Unresolved Error");
abort();
}