Use Cocoa Touch Framework in iOS and WatchKit

I have a Cocoa Touch Framework that I developed for using in both my iOS app and my WatchKit app on iOS 8. I have no problems with iOS 8, however when I move the project to iOS 9 and update the WatchKit app to run natively I get the following error:

ParkFinderKit was rejected as an implicit dependency for 'ParkFinderKit.framework' because it doesn't contain platform 'watchsimulator' in its SUPPORTED_PLATFORMS 'iphonesimulator, iphoneos'


I attempted to manually add watchossimulator and watchos to the list of supported platforms:


However this produces another error:

ParkFinderKit was rejected as an implicit dependency for 'ParkFinderKit.framework' because its SDK is platform 'com.apple.platform.iphonesimulator' and it needs to match platform 'com.apple.platform.watchsimulator'


Any ideas as to how to solve my issue?

Answered by g0ld2k in 19806022

Okay, it looks like you cannot use a Cocoa Touch Framework inside of a WatchKit app. I was able to get around this by creating a new Watch Framework target and then assigning each file from the original framework to the new framework in the Target Membership options.



This accomplishes my goal of sharing code between iOS and WatchKit without having duplicate code.

Accepted Answer

Okay, it looks like you cannot use a Cocoa Touch Framework inside of a WatchKit app. I was able to get around this by creating a new Watch Framework target and then assigning each file from the original framework to the new framework in the Target Membership options.



This accomplishes my goal of sharing code between iOS and WatchKit without having duplicate code.

This makes sense because the framework needs to be in two locations: the iPhone and the Watch. With watchOS 1 apps, the watch extension was on the iPhone so it could share a single copy of the framework.


For what it's worth, you could also have just uses the Target Membership options to add the files from your framework directly into your watchOS 2 extension without having to create a new framework. I don't think there is anything else you can share that framework with (unlike on the iPhone where a framework can be shared between an iOS app and various extensions such as Today Widgets, keyboards or watchOS 1 extensions).


But perhaps it makes more sense from a code/project structure to have a Watch Framework even though it is only used by one target (your watchOS 2 extension).

Use Cocoa Touch Framework in iOS and WatchKit
 
 
Q