首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift中的类型错误:无法将类型“[UInt64]”的值转换为预期的参数类型'inout UInt64‘

Swift中的类型错误:无法将类型“[UInt64]”的值转换为预期的参数类型'inout UInt64‘
EN

Stack Overflow用户
提问于 2018-02-07 12:01:26
回答 1查看 190关注 0票数 0

对于斯威夫特来说,我发现了一个错误:

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

我不懂"inout“的输入

代码语言:javascript
复制
/// 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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-07 12:06:26

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

代码语言:javascript
复制
hashArray.append(strHash(w))

而不是。也不要奇怪有时非常混乱的编译器错误消息:-)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48663308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档