对于斯威夫特来说,我发现了一个错误:
无法将“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
}发布于 2018-02-07 12:06:26
好吧,您不能像您预期的那样使用+=。使用
hashArray.append(strHash(w))而不是。也不要奇怪有时非常混乱的编译器错误消息:-)
https://stackoverflow.com/questions/48663308
复制相似问题