When sharing data between iPhone and Apple Watch while adhering to MVC, how do you use just one model for both ViewController.swift and InterfaceController.swift?

Previously I've used the WCSession class of the WatchConnectivity framework to share data between both view controllers (which are combined with their respective data models).


I'd like to incorporate MVC now, and both data "models" are duplicates so I'm guessing I should just have one model instead. I'm confused as to how data sharing between both devices fits into this, as I'm new to MVC and this seems to require two MVCs interacting with each other.

You can share model code between the two, but the app running on the iPhone and the app extension running on the Watch each have their own instances of model data. Like, let's say your model is a plist, you'll have plist files on the iPhone and separate plist files on the Watch. And the model controllers on the iPhone run separately from the model controllers on the watch, as if they are running on two separate computers (because they are).


To share model code, you'll need to create a shared framework. In fact, you'll need to create two shared framework targets: one will be a "Cocoa Touch Framework" target, and the other will be a "Watch Framework" target. But you can include the same Info.plist, source code, and resource files in each.


All the iOS-specific code or watchOS-specific code (which will include your WCSession delegates) needs to be outside of this shared model code.


Here's a post that talks about setting up the frameworks in more detail: http://stackoverflow.com/questions/34387128/how-to-set-up-a-project-with-shared-frameworks-between-ios-and-watchos-2-similar


To share model data, you use WCSession to transfer files or dictionaries back and forth.

When sharing data between iPhone and Apple Watch while adhering to MVC, how do you use just one model for both ViewController.swift and InterfaceController.swift?
 
 
Q