[英]Unable to get metadata for Core Data Persistent Store
I am using RESTKit backed by Core Data. 我正在使用由Core Data支持的RESTKit。 I am trying to detect whether or not I have a new core data model version.
我正在尝试检测是否有新的核心数据模型版本。 I have it set up to map changes automatically I just need to detect the migration to update the UI.
我将其设置为自动映射更改,我只需要检测迁移即可更新UI。 My code is:
我的代码是:
NSError *error;
NSURL *sourceURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Model" ofType:@"momd"]]
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:nil URL:sourceURL error:&error];
BOOL needsMigration = ![[self managedObjectModel] isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
The sourceMetadata variable is always nil and I can't seem to figure out why. sourceMetadata变量始终为nil,我似乎无法弄清楚原因。 The error message is not very helpful to me:
错误消息对我不是很有帮助:
Error Domain=NSCocoaErrorDomain Code=134000 "The operation couldn't be completed. (Cocoa error 134000.)" 错误域= NSCocoaErrorDomain代码= 134000“操作无法完成。(可可错误134000。)”
Where am I going wrong? 我要去哪里错了?
Your error is that sourceURL
is the path of your model file: 您的错误是
sourceURL
是模型文件的路径:
NSURL *sourceURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Model" ofType:@"momd"]]
That is, Model.momd
, in the app bundle. 即应用程序捆绑包中的
Model.momd
。 You need to use the path to your persistent store file, probably $SOMETHING.sqlite
and probably in your app's documents directory. 您需要使用永久存储文件的路径,可能是
$SOMETHING.sqlite
并且可能在应用程序的documents目录中。
Error 134000 is NSPersistentStoreInvalidTypeError
, which Apple describes as "Error code to denote an unknown persistent store type/format/version". 错误134000是
NSPersistentStoreInvalidTypeError
,Apple将其描述为“表示未知的持久性存储类型/格式/版本的错误代码”。 That suggests that either something's wrong with the persistent store file at your URL or that maybe it's missing. 这表明URL上的持久性存储文件出了点问题,或者可能是丢失了。 The first thing to do is look at
error
and see what NSPersistentStoreCoordinator
is trying to tell you. 要做的第一件事是查看
error
,看看NSPersistentStoreCoordinator
试图告诉您什么。 There's a good chance that it's telling you exactly what's wrong, but that you're not listening. 它很有可能会告诉您确切的问题所在,但您没有在听。
If a file exists at that URL, it might help to change the first argument to the lookup call from nil
to NSSQLiteStoreType
, or whatever store type you're using. 如果该URL上存在文件,则可能有助于将查找调用的第一个参数从
nil
更改为NSSQLiteStoreType
或您使用的任何存储类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.