新的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
}
好吧,您不能像预期的那样使用+=
。使用
hashArray.append(strHash(w))
而是。并且不要怀疑有时非常令人困惑的编译器错误消息: - (