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

推荐订阅源

F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
罗磊的独立博客
爱范儿
爱范儿
J
Java Code Geeks
博客园 - 司徒正美
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
小众软件
小众软件
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
Y
Y Combinator Blog
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
Vercel News
Vercel News

博客园 - 农民伯伯

【读书笔记】达利欧 - 《原则:应对变化中的世界秩序》 【读书笔记】余华 - 活着 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"