我正在制作一个关于数学测试随机生成器的程序。 但是当我创建一个随机操作时。我使用 arc4random_uniform() 创建了一个随机数。这是函数。
func generateQuestion() {
var randomoperation:UInt32 = arc4random_uniform(3)
if randomoperation == 0 {
operation = "+"
}
if randomoperation == 1 {
operation = "-"
}
if randomoperation == 2 {
operation = "X"
}
if randomoperation == 3 {
operation = "/"
}
}
这会产生错误“无法在 swift 中分配类型为“String”的值来键入“UILabel”” 你如何解决这个问题?
最佳答案
func generateQuestion() {
switch arc4random_uniform(4) {
case 0:
operation.text = "+"
case 1:
operation.text = "-"
case 2:
operation.text = "X"
case 3:
operation.text = "/"
default:
operation.text = ""
}
}
关于ios - 无法将类型 "String"的值分配给 swift 类型 "UILabel",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31153207/