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.
Steps:
- 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)!
- Select the watchOS framework's scheme and try to build.
Xcode reports a compile error: "Type of expression is ambiguous without more context"; project doesn't build.
Am I doing something wrong?
Attached some images for reference.

