Arnie Schwarzvogel
Arnie Schwarzvogel

Reputation: 1005

Xcode 9.2 stops compiling for < 11.0 target when using named colors

I know that named colors are supported from 11.0 but our project targets iOS 9.0 and we were able to successfully compile it using Xcode 9.0 / 9.1 because named colors were used only in storyboard and not in runtime.

After switching to Xcode 9.2 the project does not compile:

named colors do not work prior to iOS 11.0

Upvotes: 6

Views: 3870

Answers (2)

Shakeel Ahmed
Shakeel Ahmed

Reputation: 6023

enter image description here

//Please right click on Storyboard

enter image description here

//Alt+CMD+f

enter image description here

enter image description here

Now ctrl+F and paste .

color key=(.*) name=.* 

and now replace find source with this line

<color key=$1 red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>

//MARK:- OR Paste your key in key

(<color key="your key")

build and run

Upvotes: 4

Suhit Patil
Suhit Patil

Reputation: 12023

It's a newer feature so they might have stopped supporting it inside storyboard for earlier versions than iOS 11, although you can use it in code by putting iOS 11 check and it works fine.

if #available(iOS 11.0, *) {
   view.backgroundColor = UIColor(named:"CustomColor")
} else {
   // Fallback on earlier versions
   view.backgroundColor = .white
}

Upvotes: 0

Related Questions