watchOS 2 with Core Data

With watchOS 1, my understanding is that the watch extension was placed in the iOS app and so you could use a shared Core Data persistent store for both the watch app and the iOS app. (Which was done by using an app group, and making a separate framework that handled the data model for both the iOS app and watch app.)


However, with watchOS 2, the watch extension has moved onto the watch itself - so it would have its own persistent store. So how would you handle sharing data between the watch and iOS?


I saw the WWDC session on the "Watch Connectivity" framework which talks about moving data basically by transferring plist files.


So, if I had a note taking app that used Core Data, it sounds like I would need to periodically take any new notes the user made in the iOS app, store them in a plist file, then send those over to the watch app (using the Watch Connectivity framework). Then, on the watch app, I'd need to receive the information and have methods to save that to its own Core Data store.


Am I on the right track with that? Is there still any point to moving the data model into a separate framework? (I plan on making a Mac app too eventually, so that may be another reason to have the data model in it's own framework?)


Thanks for any advice.

Yes, you're exactly right in your understanding on all counts.


A few things to think about:


1) you don't want to overload the user on the watch with too much data. So maybe you don't need the watch's database to be comprehensive, including every note ever. Or perhaps you only need to show the note title and a few lines of preview, and anything more complicated kicks the user over to the phone. Not sure about your particular application.


2) you can transfer over the backing .sqllite files themselves with Watch Connectivity file transfer. Accounting for my caveat in 1) however, I'd probably steer towards a more hand-curated approach as to what gets sent over to the watch.

I'll definitely have to think about the "overloading the user with too much data" part. Keeping things lean and simple is great, but on the other hand I'd like to avoid customer support emails saying "why can't I view such and such on my watch, your app *****". 😉


I hadn't thought about transferring over the .sqlite files, but I think I'd rather have more control over what gets sent to the watch.


Doing all of this will be more work than with the watchOS 1 way, but I guess that's the tradeoff for having watch apps that can do more (and do it quickly).


Thanks for the input.

I am currently trying to set up coredata on the watch extension. My stumbling block is that I can't get the url for the .momd in the managedObjectModel right. It keeps returning nil. And I can't seem to find much, if any, official or unofficial references to setting up a coredatastack in the extension. Have you implemented this yet? If so, I'd appreciate knowing how you did it or if you have found any other resources. I hope you have found success.

try to select the model file and add target relationship to the watch extension? I m currently able to reference "mohd" now

I habe a question about this Topic. I want to create a new application but when i select watchOS App in Xcode 7 there is no checkbox for Use Core Data, this is only there when i select iOS Application. So how am i able to create the Core Data Storage in Xcode for the watch App? I searched for tutorials but all i found was for watchOS 1 and not watchOS 2. So please help me with that problem :) Thanks in advice!

watchOS 2 with Core Data
 
 
Q