3

我正在尝试使用 CoreData,但每当我尝试存储对象时,我都会收到 EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) 错误。什么可能导致此错误?作为旁注,我最初并没有创建打算使用 CoreData 的项目,所以 CoreData 是我后来添加到我的项目中的(我不知道这是否是导致问题的原因)。

    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("repliaoutput", withExtension: "momd")!
        return NSManagedObjectModel(contentsOfURL: modelURL)! //this line is where the EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) error is
    }()
4

2 回答 2

1

从您的项目树中删除repliaoutput.xcdatamodel,然后拖放repliaoutput.xcdatamodeld(注意最后的“d”)到您的项目中。清洁,构建,它应该像魅力一样运行。

于 2016-07-19T03:33:07.567 回答
0

检查是否在 modelURL 中获取路径如果您在后期创建了 Core Data,请repliaoutput在主项目目标中创建一个新的 Data 模型并再次构建
New File -> iOS - Core Data - Data Model

于 2016-04-18T03:03:01.623 回答