问题
I am in the process of porting an all iOS + WatchOS 1 app written originally in Swift 1, to the latest Xcode 8, WatchOS 3, Swift 3.
My app has an embedded framework with some common functionality that used to compile and run file for both the watchkit extension target and the ios app target.
With Xcode 8 I can no longer seem to get this to work. When I try to import
the framework in the watchkit extension code, I get the module not found
error.
Is it still possible to compile and use one single embedded framework package on both the target iOS and WatchKit extension targets? In my framework I have the target platforms set to watchos, watchsimulator, iphoneos, iphonesimulator
.
My gut says it's not possible anymore. Where originally all the code really ran on the phone itself, not that codes runs on the actual watch and the phone, you'd need to compile an embedded framework specifically for each.
回答1:
Short version: You can't. Create a duplicate target and set it to use the watch SDK.
Longer version from Apple's docs: https://developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/iOSSupport.html#//apple_ref/doc/uid/TP40014969-CH21-SW1
including:
NOTE
After you create a separate framework target for your WatchKit extension, you must manage the contents of that framework separately for both iOS and watchOS. If you add files to the iOS version of the framework, remember to add them to the watchOS version.
回答2:
I think with Xcode 11 you can use Swift Package Manager to do this without duplicate targets. Haven't done it myself yet but it is another option to look at that didn't exist when the question was asked or I initially answered.
来源:https://stackoverflow.com/questions/40659343/building-an-embedded-framework-for-watchos-and-ios-in-xcode-8-with-swift-3