惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
Y
Y Combinator Blog
V
V2EX
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
博客园 - 叶小钗
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
B
Blog
G
Google Developers Blog
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
N
Netflix TechBlog - Medium
腾讯CDC

博客园 - 农民伯伯

【读书笔记】达利欧 - 《原则:应对变化中的世界秩序》 【读书笔记】余华 - 活着 Mixin 工作原理 公链 - 达世币(Dash) 公链 - 比原链(Bytom) 公链 - Horizen 公链 - 以太坊(Ethereum) 公链 - Filecoin 公链 - EOS 公链 - 门罗币(Monero) 公链 - 比特币(Bitcoin) Git 简易手册 三大运营商手机号段发布时间汇总 中英文混排指南 - 简化版 iOS Share Extension 自定义分享界面 Mixin Messenger 源码解读 1 — — WCDB Swift 2018 年流水账 区块链代币(Token)笔记 — — 术语 【Swift 4.0】扩展 WCDB 支持 SQL 语句
【Swift 4.2】uuid 取 hashCode(与 Java/Go/Kotlin 一致) -...
农民伯伯 · 2019-02-25 · via 博客园 - 农民伯伯
extension String {

    func hashCode() -> Int32 {
        let components = self.split(separator: "-")

        var mostSigBits = Int64(components[0], radix: 16)!
        mostSigBits <<= 16

        let c1 = Int64(components[1], radix: 16)!
        mostSigBits |= c1
        mostSigBits <<= 16
        let c2 = Int64(components[2], radix: 16)!
        mostSigBits |= c2

        var leastSigBits = Int64(components[3], radix: 16)!
        leastSigBits <<= 48
        let c4 = Int64(components[4], radix: 16)!
        leastSigBits |= c4

        let hilo = mostSigBits ^ leastSigBits

        return Int32(truncatingIfNeeded: hilo>>32) ^ Int32(truncatingIfNeeded: hilo)
    }
}

在 Playground 里面用 "c2ab81d4-2226-4d0c-a49a-dc59b34f7972" 测试输出 "-145200653"