I have a class that inherits from NSManagedObject
. I'm using this object for model data and it's also being persisted.
class Foo: NSManagedObject {
@NSManaged var firstVar: String
@NSManaged var secondVar: String
let entity = NSEntityDescription.entityForName("Foo", inManagedObjectContext: managedObjectContext)
let createdManagedObject = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedObjectContext) as? Foo
}
I can create the object and get the NSManagedObject
instance, but I can't downcast it to actual class.
Actually, if I downcast it form optional value, then I will get nil value and if I downcast with unwrapping then it will crash.
When downcast with nil value debugger inspector shows type: Module.Foo, which I believe is the root of the problem.
Of course I tried with naming the class in .xcmodel inspector, tried to name Entity as Module.Foo, but the latter is not allowed as of Xcode 7 any more anyway.
All together: no success. Now I have to access Foo
object through KV, which is kind of awkward.
Anyone solved this issue yet?
EDIT: Adding the code to show creation and down-casting. I had issues with Xcode 7.0 and now same with 7.1.1