cast NSManagedObject to class -> Swift dynamic cast failed

送分小仙女□ 提交于 2019-12-07 15:36:10

问题


i hope you can help!

I have a class called Exercise:

import Foundation
import CoreData

class Exercise: NSManagedObject
{
@NSManaged var name: String
}

and created an Entity called Exercise with an attribute "name" of type String.

Now i want to access it from a ViewController:

var context = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext!
var exercise: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Exercise", inManagedObjectContext: context) as Exercise

But if i now try and run it, the codes stops in Thread1 at swift_dynamicCastClassUnconditional with "Swift dynamic cast failed"

I tried this on another project and it worked, I can't find the mistake!

Thanks in advance!

来源:https://stackoverflow.com/questions/26565112/cast-nsmanagedobject-to-class-swift-dynamic-cast-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!