我正在使用 iOS9 检查我的应用程序。
当我尝试重置数据库时出现问题。
请参阅以下代码:(位于 AppDelegate
中)
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if(persistentStoreCoordinator == nil)
{
....
....
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
[persistentStoreCoordinator lock];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
}
[persistentStoreCoordinator unlock];
}
return persistentStoreCoordinator;
}
这里的选项是..
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,nil];
此代码适用于 iOS8 及更低版本。但是当我用iOS9运行它时, 发生以下异常。
CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/…..sqlite options:{ NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; } ... returned error Error Domain=NSCocoaErrorDomain Code=522 "(null)" UserInfo={NSUnderlyingException=I/O error for database at /var/mobile/Containers/Data/Application/….sqlite. SQLite error code:522, 'not an error', NSSQLiteErrorDomain=522} with userInfo dictionary { NSSQLiteErrorDomain = 522; NSUnderlyingException = "I/O error for database at /var/mobile/Containers/Data/Application/….*.sqlite. SQLite error code:522, 'not an error'"; }
但是,如果我在现有的“选项”字典中将键值对添加为“journal_mode”=“MEMORY”
,则不会发生此错误。
问题:
“journal_mode”在选项字典中意味着什么?这是我的情况的真正问题吗?
最佳答案
所以我没有足够的声誉点来评论您的帖子。但您需要了解的关于 journal_mode
的大部分内容都可以在 here 中找到。 .
如果我的意见很重要,我永远不会使用MEMORY
,它只会让我害怕。
我建议使用DELETE
或WAN
。这两种方法都可以消除您所看到的错误,并且使用起来似乎比使用 MEMORY
更安全。
关于core-data - NSPersistentStoreCoordinator addPersistentStoreWithType : method error without journal_mode iOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32629302/