斯威夫特不能调用' =='参数类型为'(Int @lvalue [Int])'

时间:2014-10-23 19:05:15

标签: ios swift ios8

我真的很喜欢编程(所以这可能是一个非常愚蠢的问题),但我已经尝试按照udemy.com关于构建iOSapp的教程。但即使我一步一步地遵循它,它也不会让我编译。如果有人花时间帮助我,我将非常感激=)

    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
}

}

1 个答案:

答案 0 :(得分:3)

将Int与[Int]进行比较时,您应该期待这一点。

您需要更改以下行:

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

为:

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

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