I'm having difficulty with Core Data in Xcode 8 beta 1. Old applications will compile and work fine, but all new applications compile and work fine until they try to insert a new NSManagedObject.
Initially, I thought that this was due to the incorrect removal of the old xcdatamodel and the alteration of another, but after creating a completely new application and creating a simple Entity "A", I can not create an object of class A at runtime.
I tried using let a = A(context: myMOC) , which returns an error:
The NSManagedObject of class 'MyApp.A' must have a valid NSEntityDescription.
Trying the old let a = NSEntityDescription.insertNewObject(forEntityName: "A", into: context) as! A let a = NSEntityDescription.insertNewObject(forEntityName: "A", into: context) as! A returns an error:
Failed to distinguish value of type "NSManagedObject_A_" (0x7fd114626f80) to 'MyApp.A' (0x10d2fdf28).
I checked my xcdatamodel a dozen times to make sure everything was spelled correctly and created a new project to check to make sure that I did not make any mistakes when setting up the CD. Thoughts?
UPDATE: Package Contents 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" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="Coordinate" inverseName="route" inverseEntity="Coordinate" syncable="YES"/> </entity> <elements> <element name="Route" positionX="-45" positionY="0" width="128" height="75"/> <element name="Coordinate" positionX="-18" positionY="27" width="128" height="90"/> </elements> </model>
UPDATE 2: Printing managedObjectModel objects shows that the correct model is loading. However, I cannot get NSManagedObject to initialize in any new project.
ios swift xcode8 core-data
jjatie
source share