在从设备删除应用程序后,无法使用nil模型创建NSPersistentStoreCoordinator [英] Cannot create an NSPersistentStoreCoordinator with a nil model after deleting app from device

查看:228
本文介绍了在从设备删除应用程序后,无法使用nil模型创建NSPersistentStoreCoordinator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个'从设备中删除我的应用程序后,无法创建一个NIL模型'错误NSPersistentStoreCoordinator。我在iPad设备上测试iPhone应用程序。我已经把这段代码检查是否有 AppDelegate.m 中的文件:

I'm receiving an 'Cannot create an NSPersistentStoreCoordinator with a nil model' error after deleting my application from device. I'm testing an iPhone app in an iPad device. I've put this code to check if I have the file in AppDelegate.m:

- (NSManagedObjectModel *)managedObjectModel {
    if (__managedObjectModel != nil) {
        return __managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Name" withExtension:@"momd"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:[modelURL path]]) {
        NSLog(@"%@", [modelURL path]); //This is printed because file exists
    }
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return __managedObjectModel;
}

问题是 [NSManagedObjectModel initWithContentsOfURL] code>返回nil值。
我做了以下事情,没有成功:

The problem is that [NSManagedObjectModel initWithContentsOfURL] is returning nil value. I've done the following things, with no success:


  1. 使用 __ managedObjectModel更改managedObjectModel实例化= [NSManagedObjectModel mergedModelFromBundles:nil];

  2. 清除了构建文件夹和清理的项目

  3. 重新启动Xcode

  4. 已重新启动的计算机

  5. 将momd更改为妈妈

  6. .xcdatamodeld 在复制捆绑资源和编译源

  7. 重命名 .xcdatamodeld
  8. 关闭并开启设备

  9. 已删除文件夹: $ cd / Users / john / Library / Developer / Xcode / DerivedData

  10. 已将sqlite名称更改为强制数据库生成

  11. 从devine中删除(再次)应用程序

  1. Change managedObjectModel instantiation with this __managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
  2. Cleaned Build Folder and Cleaned project
  3. Restarted Xcode
  4. Restarted computer
  5. Changed "momd" to "mom"
  6. .xcdatamodeld is in Copy Bundle Resources and Compile Sources
  7. Renamed .xcdatamodeld and cleaned and closed Xcode project several times
  8. Turned off and on the device
  9. Deleted folders from: $ cd /Users/john/Library/Developer/Xcode/DerivedData
  10. Changed sqlite name for forcing database generation
  11. Deleted (again) application from devine

我一直在搜索解决方案几个小时,我仍然找不到它。

I've been searching the solution for hours, and I still cannot find it.

推荐答案

最后,在尝试解决这个问题两天后,我找到了解决方案:

Finally, after two days trying to solve this issue, I've found the solution here:

如何创建魔术的.xcdatamodeld文件夹/包?

我现在完成了一个项目,其他开发人员开始,似乎他没有推送最新的更改到repo,但这些更改是在设备中的应用程序,当我删除应用程序我删除了正确的 .xcdatamodeld 文件。问题是,我在项目中只有一个 MyApp.xcdatamodel 文件,这是有一个 momd

I'm now finishing a project that other developer started, and it seems that he didn't pushed the latest changes to the repo, but those changes were in the app in the device, and when I removed the app I deleted the right .xcdatamodeld file. The problem was that I had just a MyApp.xcdatamodel file in the project, and this was the reason of having a momd empty folder, it seems.

为了创建正确的数据模型层次结构,解决方案非常简单:

In order to create the right hierarchy of data model, the solution was quite easy:


  1. 选择 MyApp.xcdatamodel

  2. 转到编辑器>添加模型版本...

并将 MyApp.xcdatamodel 嵌入 MyApp.xcdatamodeld 。现在 momd 文件夹有 mom 文件,应用程序运行正常。现在唯一的问题是,我有两个 MyApp.xcdatamodel ,一个具有绿色选择的图标,但两个内容相同没有问题。

And this embedded the MyApp.xcdatamodel file into MyApp.xcdatamodeld. Now the momd folder has the mom files and the app runs OK. The only problem now is that I have two MyApp.xcdatamodel, one with a green selected icon, but both with the same content so no problem.

这篇关于在从设备删除应用程序后,无法使用nil模型创建NSPersistentStoreCoordinator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆