ios - swift 4,核心数据: error: Failed to load model named textTabelView

标签 ios core-data appdelegate swift4

当我在 Xcode 9 中使用 Swift4 时,给了我

2017-11-13 10:17:15.807151+0800 textTabelView[1146:53409] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} 2017-11-13 10:17:16.369075+0800 textTabelView[1146:52958] [error] error: Failed to load model named textTabelView CoreData: error: Failed to load model named textTabelView

我的代码:

@IBAction func savaArea(_ sender: UIBarButtonItem) {

    let appDelegate = UIApplication.shared.delegate as! AppDelegate

    area = AreaMO(context: appDelegate.persistentContainer.viewContext)
    area.area = areaText.text
    area.province = provinceText.text
    area.part = partText.text
    area.isVisited = visitedLabel.text
    if let imageData = UIImageJPEGRepresentation(coverImageView.image!, 0.8){
        area.image = NSData(data: imageData) as Data
    }
    print("saving...")
    appDelegate.saveContext()

    performSegue(withIdentifier: "unwindToArea", sender: self)

}

关于 CoreData 的 AppDelegat.swift:

// MARK: - Core Data stack

lazy var persistentContainer: NSPersistentContainer = {

    let container = NSPersistentContainer(name: "textTabelView")

    ...
}

我确定我确实正确导入了 CoreData。

该项目可以正常构建,但是当我触摸按钮(@IBaction 是)时,控制台中会打印警告并且应用程序崩溃

如何修复它?

最佳答案

如果 NSPercientContainer 参数的名称与 xcdatamodeld 文件的名称不匹配,您会得到同样的错误。可能的解决方案:

  1. 仔细检查数据模型是否名为“textTabelView.xcdatamodeld”,
  2. 如果名称被某些不可见字符损坏,请删除旧的 xcdatamodeld 文件并创建一个新文件,或者
  3. 清理构建应用文件夹 (⌥⇧⌘K)(即 option+shift+apple+K)。

祝你好运!

关于ios - swift 4,核心数据: error: Failed to load model named textTabelView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47256436/

相关文章:

ios - 使用 Firebase 进行身份验证自动登录

swift - 从 AppDelegate 更改 WebView url

iphone - 关闭屏幕播放声音/不要让 iPhone 进入休眠状态

ios - 使用泛型和原始类型进行类型检查?

ios - 如何将 MKMapPoint 转换为 CGPoint

ios - CoreData 父子上下文冲突管理

objective-c - 核心数据 "use scalar properties for primitive data types"复选框

ios - 使用 Swift 在 Firebase 中使用 Geofire 保存 GeoLocation

mysql - 核心数据关系可以有属性吗

ios - swift 采用的 objective-c 协议(protocol)