Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIColor(named:) always returns nil on iOS 11.0-11.2

I have a class that returns a UIColor from my custom palette. I call this programmatically but when I tested it on iOS 11 it always returns a nil result... I tried this on multiple devices and OS versions 11.0, 11.0.1, 11.2 and all of them returns nil. But as soon as I run them on >iOS 12 it always returns a correct color.

var color: UIColor? {
    switch self {
    case .darkIndigo: return UIColor(named: "darkIndigo")
    case .lightNavy: return UIColor(named: "lightNavy")
    case .cobalt: return UIColor(named: "cobalt")
    }
}

I have recently changed my bundle ID for the app... and this makes me think that it has something to do with the similar problem that UIImage has when multiple bundles are used. Especially when I get the error message

WARNING: Unable to resolve the color named "darkIndigo" from any of the following bundles:

But how is this supposed to be resolved? Should I just manually remove the whole asset catalogue and add them back?

like image 658
Giovanni Palusa Avatar asked Aug 26 '19 12:08

Giovanni Palusa


1 Answers

Edit:

This was a bug in Xcode and its fixed in the new GM Seed 2 (11A420a).


I encountered this issue as well. I was using Xcode 11 beta 6, with Command Line Tools 11.0.

I solved it by switching to Xcode 10.2.1 and Command Line Tools 10.2.1, cleaning & building again.

Xcode Command Line Tools

like image 110
Antag Avatar answered Nov 13 '22 09:11

Antag