Go to file
Yasuhiro Hatta 1998e57be6
Merge pull request #15 from yaslab/update-gitignore
Update .gitignore
2023-06-18 00:54:48 +09:00
.github/workflows Add CI settings for GitHub Actions 2022-02-06 19:32:10 +09:00
Sources Release 1.2.0 2022-02-06 09:43:38 +09:00
Tests Rename the parameter name of `init(timestamp:uuid:)` 2021-07-24 17:37:41 +09:00
ULID.xcodeproj Add CI settings for GitHub Actions 2022-02-06 19:32:10 +09:00
.gitignore Update .gitignore 2023-06-18 00:50:58 +09:00
.spi.yml Add a Swift Package Index manifest file (.spi.yml) 2023-06-18 00:36:45 +09:00
LICENSE Initial commit 2019-01-11 00:12:58 +09:00
Package.swift Update Package.swift 2023-06-18 00:30:38 +09:00
README.md Update README.md 2022-02-06 19:32:11 +09:00
ULID.swift.podspec Release 1.2.0 2022-02-06 09:43:38 +09:00

README.md

ULID.swift

Implementation of ULID in Swift.

Usage

Generate ULID

import ULID

// Generate ULID using current time
let ulid = ULID()

// Get ULID string
let string: String = ulid.ulidString
// Get ULID binary data
let data: Data = ulid.ulidData

Parse ULID

import ULID

// Parse ULID string
let ulid = ULID(ulidString: "01D0YHEWR9WMPY4NNTPK1MR1TQ")!

// Get Timestamp as Date
let timestamp: 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

let ulid = ULID(ulidString: "01D132CXJVYQ7091KZPZR5WH1X")!
let uuid = UUID(uuid: ulid.ulid)
print(uuid.uuidString) // 01684626-765B-F5CE-0486-7FB7F05E443D

From UUID to ULID

import Foundation
import ULID

let uuid = UUID(uuidString: "01684626-765B-F5CE-0486-7FB7F05E443D")!
let ulid = ULID(ulid: uuid.uuid)
print(ulid.ulidString) // 01D132CXJVYQ7091KZPZR5WH1X

Installation

CocoaPods

pod 'ULID.swift', '~> 1.2.0'

Carthage

github "yaslab/ULID.swift" ~> 1.2.0

Swift Package Manager

.package(url: "https://github.com/yaslab/ULID.swift.git", .upToNextMinor(from: "1.2.0"))

License

ULID.swift is released under the MIT license. See the LICENSE file for more info.