How to access color from an asset catalog in a shared framework in a watchOS app?

Hi there,

I have a shared framework between my iOS and watchOS apps which contains an asset catalog with some named colors. I'd like to access the named colors in my watchOS app. In iOS, I can use UIColor.init(named name: String, in bundle: Bundle, compatibleWith traitCollection: UITraitCollection) to tell the system to access the name from the passed-in Bundle.

watchOS also claims to have this initializer available since watchOS 4; however, Xcode autocomplete doesn't find it, I get a build error when I try to use it, and it's a bit odd because UITraitCollection (which is part of that method signature) isn't exposed to us in watchOS anyhow.

How can I access an asset from the asset catalog in my shared framework?
This is a hack, but I created an objc header to make the UITraitCollection definition available to watchOS.
This allowed for the UIColor(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?) method to be accessed.

Objc header file added to the framework:
Code Block
#if TARGET_OS_WATCH
@import UIKit;
@interface UITraitCollection : NSObject
@end
#endif

How to access color from an asset catalog in a shared framework in a watchOS app?
 
 
Q