Reputation: 4906
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?
Upvotes: 4
Views: 1407
Reputation: 1751
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.
Upvotes: 1
Reputation: 12109
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.
Upvotes: 2