How can we use Assets Catalog Color Sets? How can we use Assets Catalog Color Sets? swift swift

How can we use Assets Catalog Color Sets?


UIColor(named: "myColor") 

Source: WWDC 2017 Session 237 —— What's New in MapKit


Caveat: Your project's Deployment Target needs to be set to iOS 11.0.


(short answer to the question update: there is UIColor(named: "MyColor") in Xcode 9.0)

Answering the original question:

  1. you create your color set

enter image description here

  1. you find your color among your snippets and you drag-n-drop it

enter image description here

  1. it will translate to a color literal when looking at the source code:

    #colorLiteral(red: 0, green: 0.6378085017, blue: 0.8846047521, alpha: 1)

You notice how the values of red, green and blue are different? It's because I defined them using Color Space Display P3, but the colorLiteral is using Color Space sRGB.


In Xcode 11 press command + shift + L , it will open a snippet , select last one like i showed in image drag and drop .

enter image description here