gpt4 book ai didi

ios - Swift 无法使用类型为 '==' 的参数调用 '(Int @lvalue [Int])'

转载 作者:搜寻专家 更新时间:2023-11-01 06:48:29 24 4
gpt4 key购买 nike

我真的是编程新手(所以这可能是一个非常愚蠢的问题),但我已经尝试按照 udemy.com 教程学习如何构建 iOS 应用程序。但是即使我一步一步地跟着它,它也不会让我编译。如果有人愿意花时间帮助我,我将不胜感激 =)

    func getSixRandom () -> String {
var lottoBalls = [Int]()
var result = ""
var n = [Int(arc4random() % 49) + 1]

lottoBalls += n

while lottoBalls.count < 6 {
n = [Int(arc4random() & 49) + 1]
var found = false

for ball in lottoBalls {
// Throws an error!!

if ball == n {
found = true
}
}

if found == false {
lottoBalls += n
}

}

result = "\(lottoBalls[0]), \(lottoBalls[1]), \(lottoBalls[2]), \(lottoBalls[3]), \(lottoBalls[4]), \(lottoBalls[5]) "

return result
}

最佳答案

这是您在比较 Int 和 [Int] 时应该期待的结果。

您需要更改以下行:

var n = [Int(arc4random() & 49) + 1]

到:

var n = Int(arc4random() & 49) + 1

并在您设置 n 的任何其他位置执行相同的操作。

关于ios - Swift 无法使用类型为 '==' 的参数调用 '(Int @lvalue [Int])',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26535494/

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