Swiftpack.co - scru128/swift-scru128 as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by scru128.
scru128/swift-scru128 v2.1.1
SCRU128 Swift Implementation
⭐️ 0
🕓 16 hours ago
.package(url: "https://github.com/scru128/swift-scru128.git", from: "v2.1.1")

SCRU128: Sortable, Clock and Random number-based Unique identifier

GitHub tag License

SCRU128 ID is yet another attempt to supersede UUID for the users who need decentralized, globally unique time-ordered identifiers. SCRU128 is inspired by ULID and KSUID and has the following features:

  • 128-bit unsigned integer type
  • Sortable by generation time (as integer and as text)
  • 25-digit case-insensitive textual representation (Base36)
  • 48-bit millisecond Unix timestamp that ensures useful life until year 10889
  • Up to 281 trillion time-ordered but unpredictable unique IDs per millisecond
  • 80-bit three-layer randomness for global uniqueness
import Scru128

// generate a new identifier object
let x = scru128()
print(x)  // e.g. "036Z951MHJIKZIK2GSL81GR7L"
print(x.bytes)  // as a 128-bit unsigned integer in big-endian byte array

// generate a textual representation directly
print(scru128String())  // e.g. "036Z951MHZX67T63MQ9XE6Q0J"

See SCRU128 Specification for details.

Add swift-scru128 as a package dependency

To add this library to your Xcode project as a dependency, select File > Add Packages and enter the package URL: https://github.com/scru128/swift-scru128

To use this library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

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

And, include Scru128 as a dependency for your target:

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

License

Licensed under the Apache License, Version 2.0.

GitHub

link
Stars: 0
Last commit: 23 hours ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics