You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import ULID
// Generate ULID using current time
letulid=ULID()
// Get ULID string
letstring:String= ulid.ulidString
// Get ULID binary data
letdata:Data= ulid.ulidData
Parse ULID
import ULID
// Parse ULID string
letulid=ULID(ulidString:"01D0YHEWR9WMPY4NNTPK1MR1TQ")!
// Get Timestamp as Date
lettimestamp:Date= ulid.timestamp
Convert between ULID and UUID
Both ULID and UUID are 128 bit data, so you can convert strings to each other.
From ULID to UUID
import Foundation
import ULID
letulid=ULID(ulidString:"01D132CXJVYQ7091KZPZR5WH1X")!
letuuid=UUID(uuid: ulid.ulid)print(uuid.uuidString) // 01684626-765B-F5CE-0486-7FB7F05E443D
From UUID to ULID
import Foundation
import ULID
letuuid=UUID(uuidString:"01684626-765B-F5CE-0486-7FB7F05E443D")!
letulid=ULID(ulid: uuid.uuid)print(ulid.ulidString) // 01D132CXJVYQ7091KZPZR5WH1X
Installation
Swift Package Manager
Add the dependency to your Package.swift. For example:
// swift-tools-version: 5.9
import PackageDescription
letpackage=Package(
name:"MyPackage",
dependencies:[
// Add `ULID.swift` package here.
.package(url:"https://github.com/yaslab/ULID.swift.git", from:"1.3.1")],
targets:[.executableTarget(
name:"MyCommand",
dependencies:[
// Then add it to your module's dependencies.
.product(name:"ULID",package:"ULID.swift")])])
CocoaPods
pod 'ULID.swift', '~> 1.3.1'
License
ULID.swift is released under the MIT license. See the LICENSE file for more info.
About
Universally Unique Lexicographically Sortable Identifier (ULID) in Swift.