在 swift 中创建一个 UIColor 数组

Create an array of UIColor in swift

为什么这会给我一个错误?

 var colorArray = [UIColor.self]

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

如何定义一个可变数组来存储UIColor

@乔治阿斯达:

出现的错误是"Cannot convert value type 'UIColor' to expected argument type 'UIColor.Type'"

设置 UIColor 类型的空数组时错误消失,例如下面我复制了它...

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

随后,当我像您的示例中那样追加和删除 Last 并在每个阶段打印时,一切看起来都很好,没有任何错误...例如在 Func 中...

self.uiColorArray.append(UIColor.blueColor) // in Swift 3, its UIColor.blue
    print(uiColorArray)

    self.uiColorArray.removeLast()
    print(uiColorArray)

错误消失了。

更新 Swift 3

let colorArray = [UIColor.red, UIColor.green, UIColor.blue]