error description:
a "WatchKit" is not available when building for iOS. Consider using
#if !TARGET_OS_IOS
to conditionally import this framework.
這種錯誤發生在Xcode11版本以上,目前我使用的Xcode10.1沒有出現;
Xcode 11從iOS SDK中刪除了WatchKit。從發行說明:
WatchKit框架不再包含在iOS SDK中。如果您使用的是來自iOS的WatchKit API,則需要刪除此用法。WatchKit框架在watchOS上仍然可用。如果您使用iOS上的WatchKit API來推斷配對的Apple Watch上的功能是否可用,請在將反饋提交給Feedback Assistant時包括有關用例的信息。(49707950)
解決方法:
我們需要使用“條件導入”來解決此問題。
將import WatchKit
標頭替換爲以下代碼:
#if !TARGET_OS_IOS
#import <WatchKit/WatchKit.h>
#endif
紅色部分主要看Xcode給你的提示,有些是
#if !os(iOS)