簡體   English   中英

Swift無法使用類型為'(Int @lvalue [Int])'的參數調用'=='

[英]Swift cannot invoke '==' with an argument of type '(Int @lvalue [Int])'

我真的很喜歡編程(所以這可能是一個非常愚蠢的問題),但我試圖按照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
}

}

這是將Int與[Int]進行比較時應該期待的。

您需要更改以下行:

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

至:

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

並在你設置n任何其他位置做同樣的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM