我可以使用mergedModelFromBundles加载我的模型:很好。但是当我尝试使用initWithContentsOfURL:手动初始化它们时,它们是零。
我在2个项目中分享它们。此加载代码也在项目中共享的一个文件中。一切都在第一个项目中起作用,但第二个项目给了我一些问题。
NSMutableArray *models = [NSMutableArray array];
NSString *path = [[NSBundle mainBundle] pathForResource:@"MyModel" ofType:@"momd"];
if(![[NSFileManager defaultManager] fileExistsAtPath:path]){
NSLog(@"Compiled MyModel.momd file not found.");//never gets called, file is there
}
NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL: [NSURL URLWithString:path] ];
if(!model){
//this is getting called which indicates there is something wrong with the coredata file...?
NSLog(@"Could not load compiled MyModel.momd file.");
}else{
[models addObject:toolKitModel];
}
//works in project 1 where initWithContentsOfURL: returns nil but not in project 2
_managedObjectModel = [NSManagedObjectModel mergedModelFromBundles: NULL ];
//works in project 2 where initWithContentsOfURL: returns the NSManagedObjectModel but not in project 1
_managedObjectModel = [NSManagedObjectModel modelByMergingModels:models ];the models
为什么NSManagedObjectModel不会加载initWithContentsOfURL:和modelByMergingModels的任何想法:?