Watch App and Core Data
This post will be a little more technical than most on this site. I wanted to explore how to create a Watch App which shares data with its companion Phone App via Core Data. Though this seems reasonably straight forward to achieve, I didn’t see a lot of info on the developer forums. Furthermore, there were a few tricks to getting it to work that I felt were worth sharing.
Below, I cover Core Data integration with a Watch App at a high level and in the linked video and Github repository I cover the approach in full detail. I put this together in an evening, so design may be a little basic, but should provide a good jumping off point.
High Level Steps #
- Create a Core Data app using the Master/Detail iOS template
- Add a Watch App Target
- Add a shared App Group container in the Capabilities area of the project. Add the same container for each of the following:
- iPhone App
- WatchKit Extension
- Update the location of the Persistent Data Store to point to the App Group
- Create a Cocoa Touch Framework for the shared code that accesses the Core Data Store
- Move core data access code into the framework; make classes and methods public
- Build Watch App UI that consumes Core Data via the shared code in the Framework
- Build and run!
Video Walkthrough #
If you’d like to watch me create this app in 10 minutes, then check it out here.