George Asda George Asda - 1 year ago 172
iOS Question

Create an array of UIColor in swift

Why is this giving me an error?

var colorArray = [UIColor.self]

colorArray.append(UIColor.redColor()) //error here

how do I define a mutable array to store

Answer Source

@George Asda:

The error coming up is "Cannot convert value type 'UIColor' to expected argument type 'UIColor.Type'"

The error disappears when an empty array of type UIColor is set up e.g. below I have replicated it...

var uiColorArray = [UIColor]()   // Empty Array of type UIColor

Subsequently, when I append and removeLast like in your example and print at each stage, all appears fine without any error... e.g. inside a Func...



Error is gone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download