Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaslab/ULID.swift
Universally Unique Lexicographically Sortable Identifier (ULID) in Swift.
https://github.com/yaslab/ULID.swift
swift ulid
Last synced: 13 days ago
JSON representation
Universally Unique Lexicographically Sortable Identifier (ULID) in Swift.
- Host: GitHub
- URL: https://github.com/yaslab/ULID.swift
- Owner: yaslab
- License: mit
- Created: 2019-01-10T15:12:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T14:17:09.000Z (4 months ago)
- Last Synced: 2024-07-31T17:37:59.351Z (4 months ago)
- Topics: swift, ulid
- Language: Swift
- Homepage: https://swiftpackageindex.com/yaslab/ulid.swift/master/documentation/ulid
- Size: 61.5 KB
- Stars: 94
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ULID.swift
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fyaslab%2FULID.swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/yaslab/ULID.swift)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fyaslab%2FULID.swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/yaslab/ULID.swift)Implementation of [ULID](https://github.com/ulid/spec/blob/master/README.md) in Swift.
## Usage
### Generate ULID
```swift
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
```swift
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
```swift
import Foundation
import ULIDlet ulid = ULID(ulidString: "01D132CXJVYQ7091KZPZR5WH1X")!
let uuid = UUID(uuid: ulid.ulid)
print(uuid.uuidString) // 01684626-765B-F5CE-0486-7FB7F05E443D
```#### From UUID to ULID
```swift
import Foundation
import ULIDlet uuid = UUID(uuidString: "01684626-765B-F5CE-0486-7FB7F05E443D")!
let ulid = ULID(ulid: uuid.uuid)
print(ulid.ulidString) // 01D132CXJVYQ7091KZPZR5WH1X
```## Installation
### Swift Package Manager
Add the dependency to your `Package.swift`. For example:
```swift
// swift-tools-version: 5.9import PackageDescription
let package = Package(
name: "MyPackage",
dependencies: [
// Add `ULID.swift` package here.
.package(url: "https://github.com/yaslab/ULID.swift.git", from: "1.3.0")
],
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.0'
```## License
ULID.swift is released under the MIT license. See the [LICENSE](https://github.com/yaslab/ULID.swift/blob/master/LICENSE) file for more info.