Giter Site home page Giter Site logo

uuid-kit's Introduction

UUIDKit

MIT License Swift 5.1

UUIDKit is a Swift library for generating and working with Universally Unique Identifiers (UUIDs) as specified in RFC 4122.

It extends the existing Foundation's UUID type.

Generating UUIDs

The default initializer for UUID returns a random (version 4) UUID. This library adds methods for creating version 1, version 3 and version 5 UUIDs.

Time-based UUIDs (UUID.v1)

UUID.v1 returns a time-based (version 1) UUID.

let uuidv1 = UUID.v1()

Instead of relying on the computer's Ethernet address to ensure global uniqueness of time-based UUIDs, this method generates a random node identifier that is used for the duration of the program's execution, as specified in RFC 4122 section 4.5. The reason is discussed in this issue.

Random UUIDs (UUID.v4)

UUID.v4 returns a random (version 4) UUID. You may pass a custom random number generator.

var generator = SystemRandomNumberGenerator()
let uuidv4 = UUID.v4(using: generator)

Name-based UUIDs (UUID.v3 and UUID.v5)

UUID.v3 and UUID.v5 return name-based UUIDs using either MD5 (version 3) or SHA-1 (version 5) hashing.

let uuidv3 = UUID.v3(name: "thats.an.example", namespace: .dns)
let uuidv5 = UUID.v5(name: "http://example.com/index.html", namespace: .url)

Name-based UUIDs are built by combining a unique name with a namespace identifier. UUIDKit contains a list of pre-defined namespaces (.dns, .url, .oid and .x500); but any UUID may be used as a namespace.

let customNamespace = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!)

License

This project is licensed for use under the MIT License (MIT). Please see the LICENSE file for more information.

uuid-kit's People

Contributors

baarde avatar joaorgsampaio 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.