`UIColor` initializer not visible for watchOS framework

Viewed 345

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:

  1. Create a sample iOS app
  2. Add a new iOS framework to the xcodeproj. This will generate a new xcodeproj that will be added to the main one.
  3. Add a new watchOS target to the framework's xcodeproj
  4. 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)!
  1. 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.

the crash I get when trying to instantiate the colors from the assets folder the assets folder with the colors

0 Answers
Related