Uuid25:25位不区分大小写的UUID编码

GitHub tag License Swift Compatibility Platform Compatibility

Uuid25 是一种替代的 UUID 表示形式,它使用不区分大小写的 Base36 编码将 UUID 字符串缩短至 25 位。该库提供了在传统 UUID 格式与 Uuid25 之间相互转换的功能。

import Uuid25

// convert from/to string
let a = Uuid25("8da942a4-1fbe-4ca6-852c-95c473229c7d")!
assert(a.description == "8dx554y5rzerz1syhqsvsdw8t")
assert(a.hyphenated == "8da942a4-1fbe-4ca6-852c-95c473229c7d")

// convert from/to 128-bit byte array
let b = Uuid25(bytes: [UInt8](repeating: 0xff, count: 16))
assert(b.description == "f5lxx1zz5pnorynqglhzmsp33")
assert(b.bytes.allSatisfy { $0 == 0xff })

// convert from/to other popular textual representations
let c = [
  Uuid25("e7a1d63b711744238988afcf12161878")!,
  Uuid25("e7a1d63b-7117-4423-8988-afcf12161878")!,
  Uuid25("{e7a1d63b-7117-4423-8988-afcf12161878}")!,
  Uuid25("urn:uuid:e7a1d63b-7117-4423-8988-afcf12161878")!,
]
assert(c.allSatisfy { $0.description == "dpoadk8izg9y4tte7vy1xt94o" })

let d = Uuid25("dpoadk8izg9y4tte7vy1xt94o")!
assert(d.hex == "e7a1d63b711744238988afcf12161878")
assert(d.hyphenated == "e7a1d63b-7117-4423-8988-afcf12161878")
assert(d.braced == "{e7a1d63b-7117-4423-8988-afcf12161878}")
assert(d.urn == "urn:uuid:e7a1d63b-7117-4423-8988-afcf12161878")

将 swift-uuid25 添加为包依赖项

要将此库作为依赖项添加到您的 Xcode 项目,请选择 File > Add Packages 并输入包 URL:https://github.com/uuid25/swift-uuid25

要在 SwiftPM 项目中使用此库,请将以下行添加到您的 Package.swift 文件中的 dependencies

.package(url: "https://github.com/uuid25/swift-uuid25", from: "<version>"),

并且,将 Uuid25 作为目标的依赖项包含进来

.target(
  name: "<target>",
  dependencies: [.product(name: "Uuid25", package: "swift-uuid25")]
)

许可

根据 Apache License, Version 2.0 获得许可。

另请参阅