The customer originally had an online app, but because he was not satisfied, he asked us to develop a new one.
Now that the development is basically completed, the customer made a new request to continue the coredata data in the old App.
So I used the same Bundle ID and Bundle Name as the old APP, copied the .xcdatamodeld file to bundle请输入代码
, and used the same coredata code, but the url of momd could not be obtained in managedObjectModel. After checking the contents of the bundle package,
xcdatamodeld in the old app was compiled into a bunch of momd folders, and there were a bunch of mod files in the folder. However, xcdatamodeld is not compiled in the new app. Could you please tell me why this folder does not exist?
- (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;
}
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
Hahaha, it’s compiled, thank you very much