And, once again, if you’ve dealt with having to embed images across bundles, you’ll know what the issue is: The problem is much less straightforward for colour references in Storyboards and XIBs. A global property for easy reference let colorFrameworkBundle = Bundle(identifier: "")! // In your ViewController: lorText = UIColor(named: "PrimaryText", in: colorFrameworkBundle, compatibleWith: nil)
Whenever you call UIColor(named:), simply ensure to set the optional in bundle: parameter.
On the code side of things, there’s an easy fix. In iOS apps, the main bundle takes precedence by default and could be the only place where your app looks for resources, unless told otherwise. If you are familiar with the way, for instance, UIImage(named:) works, you’ll know what’s going on. The moment we linked our framework to an app and tried to refer to any of the named colours, they stopped working entirely. Remember how we mentioned we were excited to extract our semantic colour references into a reusable framework? What felt like an inarguably good architectural decision turned out to have major side effects. Below are some of the issues we’ve found with iOS 11’s Colour Assets and the ways you can deal with them.
If you are interested in developing a similar setup for your app, it’s important you know that consistent and designer-friendly colour management comes at a cost. However, this is also where we began to discover some of the rough edges of this feature. We went as far as extracting this into its own separate framework that we could share across different projects, as a “drop-in” design-approved colour scheme for any app. Voilà! Once you’ve got your pipeline set up, you can keep track of any changes to your colour semantic definitions with git and still take advantage of the power that colour assets deliver. The immediate benefit of adopting iOS 11’s Colour Assets is very clear: it makes it possible to define a colour constant that’s accessible from both your code and your Interface Builder documents. This is where named colour assets come in! Semantic Colours
When a major release of iOS introduces a new style convention, it’s frustrating for a non-developer to hear that it can’t be immediately adopted, because a “simple” colour change to all buttons in the app is near impossible to do quickly and comprehensively. It was important for us to keep the Xero app’s design language consistent and polished, while also allowing it to evolve over time. Mistakes happen, wrong shades of blue or grey inevitably slip into production builds, resulting in unhappy designers and frustrated developers. While this may not sound like a big problem, it becomes one at the scale of a sizeable mobile project, with multiple distributed teams working on it simultaneously. This solves the problem of referencing the right RGB values in your code, but doesn’t really help if you use Storyboards and XIBs, where you need to continue picking colours manually. Most developers opt for defining colour constants in code, under a Theme namespace, or something of similar nature. But until recently, you were limited to homegrown or third-party solutions for managing the colours you use in your app’s UI. You’ve been able to use Xcode Asset Catalogs to manage your images and other file-based resources since iOS 7. We, on the other hand, were most intrigued by one of the minor features of iOS 11 SDK which received almost no on-stage attention: named colours. At last year’s annual Apple developer conference WWDC, the majority of the iOS developer community was excited to play around with ARKit and all the immersive virtual experiences you could create with it.