How come I can cast to NSManagedObject but not to my entity's type?

后端 未结 8 1470
粉色の甜心
粉色の甜心 2020-12-01 13:36

I\'m using the Swift boilerplate code for Core Data in a fresh project. My .xcdatamodeld file has a single entity defined (Task) with a single attr

8条回答
  •  隐瞒了意图╮
    2020-12-01 14:25

    Xcode 7 + Swift 2

    Person.swift

    @objc(Person)
    class Person: NSManagedObject {
    }
    

    Data model

    Then simply call

    let person = NSEntityDescription.insertNewObjectForEntityForName("Person", inManagedObjectContext: self.managedObjectContext) as! Person
    

提交回复
热议问题