According to Apple's video about what's new in the CoreData frame: 38 minutes (WWDC2014 session), the inspector data model has a class name prefix with the project name. Like projectName.Doctor
I tried this, but it happens that the created managed object class becomes: projectName.swift instead of Doctor.swift . Even the class declaration becomes class projectName: ManagedObject
Decision:
In the data model inspector, simply specify the name and class of your object, what name you want, example: Doctor
After creating the object model and selecting Swift, this will create a file ( Doctor.swift ).
Now, when inserting new records into Core Data, you may encounter the error of the experience “Class not found using NSManagedObject by default”, even if you added the newly inserted object to the correct object name.
To solve this problem, simply add @objc (class name) above the class declaration. See the example below.
import Foundation import CoreData @objc(Doctor) class Doctor: NSManagedObject { @NSManaged var name: String }
Then:
let doctorManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Doctor", inManagedObjectContext: context) as Doctor doctorManagedObject.name = "John"
Save context to fix insert.
Zaldy Sep 22 '14 at 9:58 a.m. 2014-09-22 09:58
source share