Xcode reports a compile error when trying to instantiate a UIColor using init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)
on a watchOS framework.
脚步:
- Create a sample iOS app
- Add a new iOS framework to the xcodeproj. This will generate a new xcodeproj that will be added to the main one.
- Add a new watchOS target to the framework's xcodeproj
- Create a .swift file where you declare a UIColor instantiated using
init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)
and set the target membership to both the iOS and watchOS frameworks.
let bundle = Bundle(identifier: "com.alexdmotoc.MyKit")
let myColor1 = UIColor(named: "MyColor1", in: bundle, compatibleWith: nil)!
- 选择watchOS框架的方案并尝试构建。
Xcode报告一个编译错误:“表达式的类型是模棱两可的,没有更多上下文”。项目没有建立。
难道我做错了什么?
随附一些图像以供参考。