我正在查看 String ( https://github.com/apple/swift/blob/master/stdlib/public/core/String.swift ) 的 Swift 实现
String实现了Hashable协议(protocol),也就是说它必须提供一个hashValue。但是,上面链接的 String 实现中没有提供任何内容。我在哪里可以找到这个?我假设 String 从某处继承了它。
最佳答案
引用Swift String - Relationships提到的内容,你完全正确:
String implements the Hashable protocol...
您在问题中提供的文件的链接中看不到符合 Hashable
协议(protocol)的实现的原因是:
'String : Hashable'
一致性已移至单独的文件。你可以在这里找到它:
https://github.com/apple/swift/blob/master/stdlib/public/core/StringHashable.swift ;请注意,该文件是 StringHashable.swift,但不是 String.swift。
您还可以在此处找到此更改的提交: https://github.com/apple/swift/pull/4612/commits
关于swift - Swift 如何哈希字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878471/