Swift 无法调用非函数类型[UIColor]的值
我已将此代码写入Swift,但最后一行代码返回此错误消息: 无法调用非函数类型“[UIColor]”的值Swift 无法调用非函数类型[UIColor]的值,swift,Swift,我已将此代码写入Swift,但最后一行代码返回此错误消息: 无法调用非函数类型“[UIColor]”的值 你犯了一些语法错误颜色(posicion)应该是颜色[posicion] struct Colores { let colores = [UIColor(red: 210/255.0, green: 90/255.0, blue: 45/255.0, alpha: 1), UIColor(red: 40/255.0, green: 170/255.0, blue: 45/255.
你犯了一些语法错误<代码>颜色(posicion)应该是
颜色[posicion]
struct Colores {
let colores = [UIColor(red: 210/255.0, green: 90/255.0, blue: 45/255.0, alpha: 1),
UIColor(red: 40/255.0, green: 170/255.0, blue: 45/255.0, alpha: 1),
UIColor(red: 3/255.0, green: 180/255.0, blue: 90/255.0, alpha: 1),
UIColor(red: 210/255.0, green: 190/255.0, blue: 5/255.0, alpha: 1),
UIColor(red: 120/255.0, green: 120/255.0, blue: 50/255.0, alpha: 1),
UIColor(red: 130/255.0, green: 80/255.0, blue: 90/255.0, alpha: 1),
UIColor(red: 130/255.0, green: 130/255.0, blue: 130/255.0, alpha: 1),
UIColor(red: 3/255.0, green: 50/255.0, blue: 90/255.0, alpha: 1)]
func regresaColorAleatorio() -> UIColor{
let posicion = Int(arc4random()) % colores.count
return colores[posicion]
}
}
你犯了一些语法错误<代码>颜色(posicion)应该是
颜色[posicion]
struct Colores {
let colores = [UIColor(red: 210/255.0, green: 90/255.0, blue: 45/255.0, alpha: 1),
UIColor(red: 40/255.0, green: 170/255.0, blue: 45/255.0, alpha: 1),
UIColor(red: 3/255.0, green: 180/255.0, blue: 90/255.0, alpha: 1),
UIColor(red: 210/255.0, green: 190/255.0, blue: 5/255.0, alpha: 1),
UIColor(red: 120/255.0, green: 120/255.0, blue: 50/255.0, alpha: 1),
UIColor(red: 130/255.0, green: 80/255.0, blue: 90/255.0, alpha: 1),
UIColor(red: 130/255.0, green: 130/255.0, blue: 130/255.0, alpha: 1),
UIColor(red: 3/255.0, green: 50/255.0, blue: 90/255.0, alpha: 1)]
func regresaColorAleatorio() -> UIColor{
let posicion = Int(arc4random()) % colores.count
return colores[posicion]
}
}
嗯,我想这是因为你试图调用
colors(position)
,这不是一个函数(正如错误所说)。另外请注意,我修复了您对非英语变量的滥用。嗯,我想这是因为您试图调用colors(position)
,这不是一个函数(如错误所示)。还请注意,我修复了您对非英语变量的滥用。