GithubHelp home page GithubHelp logo

voncannon / ulid.swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yaslab/ulid.swift

0.0 0.0 0.0 65 KB

Universally Unique Lexicographically Sortable Identifier (ULID) in Swift.

Home Page: https://swiftpackageindex.com/yaslab/ulid.swift/master/documentation/ulid

License: MIT License

Ruby 2.19% Objective-C 1.00% Swift 96.81%

ulid.swift's Introduction

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.

ulid.swift's People

Contributors

yaslab avatar mufumade avatar adamrothman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.