gpt4 book ai didi

ios - 无法将类型 "String"的值分配给 swift 类型 "UILabel"

转载 作者:行者123 更新时间:2023-11-29 01:53:26 25 4
gpt4 key购买 nike

我正在制作一个关于数学测试​​随机生成器的程序。但是当我创建一个随机操作时。我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com