【问题标题】:Type Error in Swift :Cannot convert value of type '[UInt64]' to expected argument type 'inout UInt64'Swift 中的类型错误:无法将类型“[UInt64]”的值转换为预期的参数类型“inout UInt64”
【发布时间】:2018-07-17 17:07:59
【问题描述】:

Swift 新手,我收到了这个错误:

无法将类型“[UInt64]”的值转换为预期的参数类型“inout UInt64”

我不明白“inout”打字

/// non crypto hash
func strHash(_ str: String) -> UInt64 {
    var result = UInt64 (5381)
    let buf = [UInt8](str.utf8)
    for b in buf {
        result = 127 * (result & 0x00ffffffffffffff) + UInt64(b)
    }
    return result
}

let myString: String = "Hello World"

let words = myString.components(separatedBy: " " )
print(words)
var hashArry = [UInt64]()
for w in words {
    hashArry += strHash(w) // <<<<<<<<< Here
}

【问题讨论】:

    标签: swift swift4


    【解决方案1】:

    好吧,您不能像预期的那样使用+=。 使用

    hashArray.append(strHash(w))
    

    相反。并且不要怀疑有时非常令人困惑的编译器错误消息:-)

    【讨论】:

    • 谢谢!我确实看到了那个方法,但没有把 0b10 和 0b10 放在一起!感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    相关资源
    最近更新 更多