【问题标题】:Cannot find managedObjectModel找不到 managedObjectModel
【发布时间】:2015-10-30 05:28:59
【问题描述】:

这段代码使我的应用程序崩溃

lazy var managedObjectModel: NSManagedObjectModel = {

    // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.

    let modelURL = NSBundle.mainBundle().URLForResource("appTest", withExtension: "momd")!
    return NSManagedObjectModel(contentsOfURL: modelURL)!
}()

特别是在let modelURL = 赋值(我放置了断点)

与:

fatal error: unexpectedly found nil while unwrapping an Optional value

所以我认为这可能意味着

1- 找不到 appTest.momd 文件,因为名称更改或

2- 它只是尚未创建。

有什么想法吗?

【问题讨论】:

  • 您确定您的项目中包含appTest.momd 文件吗?
  • 而且,请告诉我,错误信息是什么?
  • @Alexander 我该如何检查?
  • @JodyHagins 我刚刚编辑了我的问题,出现了错误

标签: ios swift core-data nsmanagedobject


【解决方案1】:

这看起来像是拼写错误。最有可能的是,您的模型被称为“AppTest”而不是“appTest”。

您应该能够通过选择项目导航器底部的搜索框并开始键入文件名来找到模型。它应该以.xcdatamodeld 结尾。

如果缺少,请将“数据模型”类型的新文件添加到项目中,并确保名称匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2014-09-25
    • 2012-02-02
    • 2012-03-02
    相关资源
    最近更新 更多