That's what I'm doing:
Now i have
- IPhone app
- WatchKit Extension
- A Cocoa Touch Framework that contains all my common classes
What I would like to accomplish has a persistent storage (master data), which is shared between my iPhone application and WatchKit Extension.
So this is what I have done so far
- Create an application group to have a common container.
- Add a basic data model (Model.xcdatamodeld) to my Touch Cocoa construct.
- One entity created in this model.
- Subclassed NSMangedObject for this object and added to my Cocoa Touch Framework
- Added DataManager class for my Cocoa Touch Framework
This is what the initializer in my DataManager looks like
public init() { let sharedContainerURL: NSURL? = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.company.Project") if let sharedContainerURL = sharedContainerURL { let storeURL = sharedContainerURL.URLByAppendingPathComponent("Model.sqlite") MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreAtURL(storeURL) let station: Station? = Station.MR_createEntity() } }
Problem i am facing
When I launch my DataManager from the AppDelegate app for iPhone, no crash occurs, but station will be null.
When replacing the last line with let stations: [Station]? = Station.MR_findAll() as? [Station] let stations: [Station]? = Station.MR_findAll() as? [Station] let stations: [Station]? = Station.MR_findAll() as? [Station] application crashes and displays the following error: A fetch request must have an entity.
I searched all the SO and Magical Records issues on GitHub but couldn't find anything to push me in the right direction. All help is much appreciated.
cocoa-touch swift watchkit core-data magicalrecord
Pim
source share