4

I'm updating one of my apps with Xcode 7 to Swift 2.0.

My app on Xcode 6 and Watch OS 1 used a Cocoa Touch framework to share a Core Data model between iOS app and WatchKit extension.

With Swift 2.0 and Xcode 7 I noticed that my framework is no longer recognized in my WatchKit extension, I get

No such module Model

in

import Model 

I read something about that on the web and one workaround it's to created a Watch Framework:

I try this way and now both iOS app and WatchKit extension can see the framework.

1) Cocoa Touch frameworks are no more compatible with WatchKit extensions or I'm missing something else?


UPDATE

2) Where I should put my Core Data model? My app should be usable without Apple Watch app also, even if the user has only an iOS device. Which type of framework or workaround I need?

ccjensen
  • 4,578
  • 2
  • 23
  • 25
Massimo Polimeni
  • 4,826
  • 4
  • 27
  • 54

2 Answers2

2

In watchOS 1.0 the watch app extension was executed on the iPhone so frameworks built for iPhone were also available for the watchOS extension.

In watchOS 2.0 the watch app extension is no longer executed on the iPhone but on the Watch. Frameworks built for iOS are not compatible with watchOS as iOS and watchOS are different operating systems.
By building your framework for watchOS your framework is able to run on the Watch.


Note for using CoreData in watchOS 2.0: if you want to share your data model with your watch in watchOS 2.0, you have to synchronize the data between the watch and the phone because of the fact that your watch app extension is now executed on your watch and core data models are stored on the internal storage of the watch.
Palle
  • 11,511
  • 2
  • 40
  • 61
  • Ok, my suspects are confirmed. Just one thing: if I created a Watch framework but the user use just the iOS app? Because my app can be usable without Watch also, just on on the iOS device. Where I should put my Core Data? I updated my question :) – Massimo Polimeni Sep 21 '15 at 08:47
1

As @blobbfuesch wrote they are not compatible because with the advent of watchOS 2 they are executed on different operation systems so you need to create a separate Watch framework.

At first I faced a problem of duplicating code between frameworks (mostly it were models) and solved it by creation of a "Shared Framework Code" folder where all shared code has been placed and "Target membership" checkboxes were selected for 2 frameworks (Cocoa Touch and Watch).

update This one is your case: Using Core Data with watchOS 2.0

You should use WatchConnectivity in particular the WCSession class to synchronise your data between Watch and Phone. They have separate file systems so you need to duplicate your data between them but this doesn't apply to code as I mentioned above.

Community
  • 1
  • 1
Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37