6

I have an app which uses core data and i'm trying to add a today extension to it which also access the data I have it set up so far and its able to access the data, but i'm having trouble with the classes for the entities. I get the following error

CoreData: warning: Unable to load class named 'Med_Track_2.Medicine' for entity 'Medicine'

Med_Track_2 is the product name for the main app, Medicine_Tracker_2 is the name for the extension The medicine class is added to both targets

Is there a way around this?

udondan
  • 57,263
  • 20
  • 190
  • 175
Ceri Turner
  • 830
  • 2
  • 12
  • 36

1 Answers1

2

You have to share the resources between your app and your extension. Read the "Sharing Data with Your Containing App" chapter: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1

Also you have to add the files you want to use to the Extension's target too. (Edit the Build phases / Compile Sources sections of the extension's target)

Dávid Kaszás
  • 1,877
  • 1
  • 16
  • 20
  • ok, so that says to use a framework, but even with a framework i get the unable to load class error – Ceri Turner Sep 18 '14 at 13:53
  • Did you edit the Extensions Target to link with that framework? – Dávid Kaszás Sep 18 '14 at 13:54
  • yeah, both the extension and the main app are linked, main app works but the extension doesn't – Ceri Turner Sep 18 '14 at 13:56
  • changing the class name to the extensions project makes the extension work (though no data is showing) but the main app then errors – Ceri Turner Sep 18 '14 at 14:04
  • and when using it from the extension no data is being shown and the fetchedresultscontroller has no returned objects – Ceri Turner Sep 18 '14 at 14:17
  • Did you build the framework to arm64 too? Did you set the app groups as explained in the link above? – Dávid Kaszás Sep 18 '14 at 14:27
  • I think you have to read the whole App Extension guide before you continue, to understand the whole concept, maybe watch the latest WWDC videos about the extensions. – Dávid Kaszás Sep 18 '14 at 14:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/61507/discussion-between-ceri-turner-and-kaszas-david). – Ceri Turner Sep 18 '14 at 15:52
  • ok, i've got past that error but i'm getting an error when trying to create an object the code is let instance = Singleton.sharedInstance NSLog("MOC: %@", instance.moc) var med : Medicine = NSEntityDescription.insertNewObjectForEntityForName("Medicine", inManagedObjectContext: instance.moc) as Medicine but its crashing with exc_breakpoint exc_arm_breakpoint console output is 2014-09-18 16:38:55.974 Med Track 2[8103:140340] MOC: so i know the managed object context is ok – Ceri Turner Sep 18 '14 at 16:03