3

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!

iVentis
  • 833
  • 6
  • 18
  • 9
    Did you set the class in the Model editor. You need to set the class using swift module. If the name of your project is MyApp. Then you would set the class name to MyApp.Exercise and then this cast will work. – Sandeep Oct 25 '14 at 17:26
  • 1
    YOU SIR are a a true hero!!! Thank you very much! i knew i forgot something!! – iVentis Oct 25 '14 at 17:31
  • possible duplicate of [Unabled to find specific subclass of NSManagedObject](http://stackoverflow.com/questions/25076276/unabled-to-find-specific-subclass-of-nsmanagedobject) – Martin R Oct 25 '14 at 17:37
  • yes, i'm sorry, i searched the wrong keywords! – iVentis Oct 25 '14 at 17:39

0 Answers0