0

I have an app with CoreData written in obj-c and created a new VC in Swift. I want to create a new "Location" in my swift VC and "Location" is a managedObject in obj-c. I have Location.h in my bridging header.

let newLocation = Location()

error:

CoreData: error: Failed to call designated initializer on NSManagedObject class 'Location' 
-[Location setLocation:]: unrecognized selector sent to instance 0x7fa5928a4880
julien
  • 437
  • 4
  • 9
  • 4
    Have a look at the [documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/): *"If you instantiate a managed object directly, you must call the designated initializer (initWithEntity:insertIntoManagedObjectContext:)."* – Martin R Feb 04 '16 at 19:00
  • Yes, I was looking at that and was still confused. After looking into it a little more I got it to work. Thank you. – julien Feb 04 '16 at 19:39
  • let newLocation = Location.init(entity: NSEntityDescription.entityForName("Location", inManagedObjectContext: Stack.sharedInstance().managedObjectContext)!, insertIntoManagedObjectContext: Stack.sharedInstance().managedObjectContext) – julien Feb 04 '16 at 19:40

0 Answers0