客户原本有一个上线的app,因为不满意于是找我们重新开发了一个。
现在开发基本完成了,客户提了一个新要求要延续旧App中的coredata数据。
于是使用了与旧APP相同的Bundle ID与Bundle Name,拷贝了.xcdatamodeld文件到bundle请输入代码
,用了一样的coredata代码,但是在managedObjectModel中无法获取momd的url。查看了一下bundle包内容,老的app中
xcdatamodeld编译成了一堆momd文件夹,文件夹中有一堆mod文件。而新的app中xcdatamodeld没有编译,请问大神为什么这个文件夹会不存在?
- (NSManagedObjectModel *)managedObjectModel{
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AirBoxModel" withExtension:@"momd"];
NSLog(@"modelURL is %@", modelURL);//显示nil
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"AirBoxModel.sqlite"];
NSLog(@"storeURL is %@",storeURL);
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
PHP中文网2017-05-02 09:39:47
I am also encountering such a problem now. The problem occurred after I imported something using cocoapods.
The .momd file is no longer generated in the .app file, so NSManagedObjectModel cannot be initialized. There is no way now. I can only import xcdatamodeld in build phases->compile sources. I still have the model files generated by the system. It’s useful, but if you can’t find the reason, it’s just like this