我在Xcode 8 beta 1中遇到了Core Data的困难.旧的应用程序将编译并运行良好,但所有新应用程序编译并运行正常,直到尝试插入新的NSManagedObject.
最初我认为它与错误地删除旧的xcdatamodel并重新构建另一个有关,但在制作一个全新的应用程序并制作一个简单的实体"A"之后,我无法在运行时创建类A的对象.
我试过使用let a = A(context: myMOC)哪个返回错误:
类"MyApp.A"的NSManagedObject必须具有有效的NSEntityDescription.
尝试旧的let a = NSEntityDescription.insertNewObject(forEntityName: "A", into: context) as! A返回错误:
无法将"NSManagedObject_A_"(0x7fd114626f80)类型的值转换为"MyApp.A"(0x10d2fdf28).
我已经检查了我的xcdatamodel十几次,以确保我拼写正确的一切,并创建了一个新项目进行测试,以确保我没有在设置CD时出错.思考?
更新: xcdatamodel包内容是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="11147.23" systemVersion="16A201w" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Coordinate" syncable="YES" codeGenerationType="class">
<attribute name="latitude" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="longitude" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES" syncable="YES"/>
<relationship name="route" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Route" inverseName="coordinates" inverseEntity="Route" syncable="YES"/>
</entity>
<entity name="Route" syncable="YES" codeGenerationType="class">
<attribute name="uuid" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="coordinates" …Run Code Online (Sandbox Code Playgroud)