Swift error: Can't assign value of type UIColor to type CGColor

For a CALayer, use, as an example:

UIColor.blue.cgColor

In general, layers/ CALayers use CG (Core Graphics) colors. While for something like background of the view, you can use something like view.backgroundColor = .blue . UIColor is part of UIKit FrameWork (NSObject), CG is part of Core Graphic (CF/ Core Foundation Library)

Note: for very old versions of Swift (Swift 1 and 2), you would have use:

UIColor.blueColor().CGColor

Tags:

Ios

Swift

Swift2