search

Home  >  Q&A  >  body text

objective-c - IOS开发了一个新应用,使用相同Bundle ID替换了旧应用,想延用旧的coredata数据,无法找到momd

客户原本有一个上线的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;
}
为情所困为情所困2758 days ago708

reply all(2)I'll reply

  • PHP中文网

    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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-02 09:39:47

    Hahaha, it’s compiled, thank you very much

    reply
    0
  • Cancelreply