### Generate Name-based UUIDs (v3 and v5) in Swift Source: https://github.com/baarde/uuid-kit/blob/main/README.md Creates version 3 (MD5) or version 5 (SHA-1) UUIDs by combining a name with a predefined or custom namespace. ```swift let uuidv3 = UUID.v3(name: "thats.an.example", namespace: .dns) let uuidv5 = UUID.v5(name: "http://example.com/index.html", namespace: .url) ``` -------------------------------- ### UUID.v3() — Generate a name-based UUID using MD5 Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a deterministic version 3 UUID by hashing a namespace UUID and a name string (or byte collection) with MD5. Given the same namespace and name, the result is always identical. Prefer `UUID.v5()` (SHA-1) for new applications unless backward compatibility is required. ```APIDOC ## UUID.v3() ### Description Generates a deterministic version 3 UUID by hashing a namespace UUID and a name string (or byte collection) with MD5. Given the same namespace and name, the result is always identical. Prefer `UUID.v5()` (SHA-1) for new applications unless backward compatibility is required. ### Usage ```swift import UUIDKit // Using a pre-defined namespace let uuid = UUID.v3(name: "thats.an.example", namespace: .dns) // Always produces: "90FF3DC0-7BBE-3132-9EFC-17D6828D50DB" let urlUUID = UUID.v3(name: "http://example.com/index.html", namespace: .url) // Custom namespace let customNS = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) let custom = UUID.v3(name: "my-resource-id", namespace: customNS) // Accepts raw bytes or Data in addition to String let bytes: [UInt8] = [0x74, 0x65, 0x73, 0x74] let fromBytes = UUID.v3(name: bytes, namespace: .dns) // Typed wrapper — parse/validate existing UUIDs let typed = UUIDv3("90ff3dc0-7bbe-3132-9efc-17d6828d50db") let invalid = UUIDv3("712869ea-f10f-40b7-b192-4f8653973806") // nil — not v3 ``` ``` -------------------------------- ### Inspect UUID Metadata (Variant and Version) Source: https://context7.com/baarde/uuid-kit/llms.txt Extensions on Foundation's UUID type to expose RFC 4122 variant and version number. Useful for runtime inspection of UUID structure. Non-RFC-4122 variants return nil for version. ```swift import UUIDKit // Inspect a standard RFC 4122 UUID let uuid = UUID(uuidString: "712869EA-F10F-40B7-B192-4F8653973806")! uuid.variant // .rfc4122 uuid.version // Optional(4) // The null UUID (all zeros) UUID.null.variant // .reservedNCS UUID.null.version // nil // Non-RFC-4122 variants return nil for version let ms = UUID(uuidString: "00000131-0000-0000-c000-000000000046")! ms.variant // .reservedMicrosoft ms.version // nil let future = UUID(uuidString: "ffffffff-ffff-ffff-ffff-ffffffffffff")! future.variant // .reservedFuture future.version // nil // Check version at runtime before using typed wrapper let unknown = UUID() // random v4 from Foundation if unknown.variant == .rfc4122, unknown.version == 1 { let v1 = UUIDv1(rawValue: unknown) } ``` -------------------------------- ### UUIDv1 Node and ClockSequence Usage Source: https://context7.com/baarde/uuid-kit/llms.txt Demonstrates the usage of UUIDv1.Node and UUIDv1.ClockSequence for generating and manipulating version 1 UUIDs. The node identifier is constant within a process run. Clock sequence increments to prevent collisions when the clock is not monotonic. ```swift import UUIDKit // Node is constant within a process run let uuid1 = UUIDv1() let uuid2 = UUIDv1() assert(uuid1.node == uuid2.node) // same node assert(uuid1 != uuid2) // different timestamps // Generate a random node explicitly let randomNode = UUIDv1.Node.random() var rng = SystemRandomNumberGenerator() let customNode = UUIDv1.Node.random(using: &rng) // Build a v1 UUID from explicit components let timestamp = UUIDv1.Timestamp(Date()) let clock = UUIDv1.ClockSequence.random() let node = UUIDv1.Node.current let manual = UUIDv1(timestamp: timestamp, clockSequence: clock, node: node) // Clock sequence increments when timestamps collide let next = clock.next ``` -------------------------------- ### Generate Name-Based UUID (v3 MD5) Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a deterministic version 3 UUID by hashing a namespace UUID and a name with MD5. The result is always identical for the same inputs. Accepts String, Data, or byte arrays for the name. Typed wrappers can parse and validate existing UUIDs, returning nil if the version does not match. ```swift import UUIDKit // Using a pre-defined namespace let uuid = UUID.v3(name: "thats.an.example", namespace: .dns) // Always produces: "90FF3DC0-7BBE-3132-9EFC-17D6828D50DB" let urlUUID = UUID.v3(name: "http://example.com/index.html", namespace: .url) // Custom namespace let customNS = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) let custom = UUID.v3(name: "my-resource-id", namespace: customNS) // Accepts raw bytes or Data in addition to String let bytes: [UInt8] = [0x74, 0x65, 0x73, 0x74] let fromBytes = UUID.v3(name: bytes, namespace: .dns) // Typed wrapper — parse/validate existing UUIDs let typed = UUIDv3("90ff3dc0-7bbe-3132-9efc-17d6828d50db") let invalid = UUIDv3("712869ea-f10f-40b7-b192-4f8653973806") // nil — not v3 ``` -------------------------------- ### Define Custom Namespace for Name-based UUIDs in Swift Source: https://github.com/baarde/uuid-kit/blob/main/README.md Allows the creation of a custom namespace UUID for generating name-based UUIDs. ```swift let customNamespace = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) ``` -------------------------------- ### Generate UUIDv5 with SHA-1 Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a deterministic version 5 UUID by hashing a namespace UUID and a name with SHA-1. Supports standard and custom namespaces, and can accept Data or [UInt8] as input. ```swift import UUIDKit // Standard namespaces: .dns, .url, .oid, .x500 let uuid = UUID.v5(name: "test.test", namespace: .dns) // Always produces: "783D51C2-94CD-5E7A-8AFE-C2FD6D91F7A2" let urlUUID = UUID.v5(name: "http://example.com/index.html", namespace: .url) let oidUUID = UUID.v5(name: "1.2.3.4.5", namespace: .oid) // Custom namespace from any UUID let customNS = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) let custom = UUID.v5(name: "my-resource", namespace: customNS) // Works with Data and [UInt8] too import Foundation let data = Data([0x68, 0x65, 0x6c, 0x6c, 0x6f]) let fromData = UUID.v5(name: data, namespace: .url) // Typed wrapper let typed = UUIDv5("783d51c2-94cd-5e7a-8afe-c2fd6d91f7a2") let invalid = UUIDv5("712869ea-f10f-40b7-b192-4f8653973806") // nil — not v5 ``` -------------------------------- ### Generate Time-Based UUID (v1) Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a version 1 UUID using current system time and a process-wide node identifier. Use the typed wrapper for full field access and parsing. Ensure the input string is a valid v1 UUID for successful parsing. ```swift import UUIDKit // Simple time-based UUID generation let uuid = UUID.v1() // e.g. "D2989D1A-3BF9-11EC-BDB7-4D10858C27B2" // Using the typed wrapper for full field access let typed = UUIDv1() print(typed.rawValue) print(typed.timestamp.rawValue) print(typed.clockSequence.rawValue) print(typed.node.rawValue) // Parse an existing v1 UUID string (returns nil if not v1) let parsed = UUIDv1("d2989d1a-3bf9-11ec-bdb7-4d10858c27b2") // parsed?.timestamp.rawValue == 0x1ec3bf9d2989d1a // parsed?.clockSequence.rawValue == 0x3db7 // parsed?.node.rawValue == 0x4d10858c27b2 // Use RawRepresentable init to wrap an existing Foundation UUID let raw = UUID(uuidString: "d2989d1a-3bf9-11ec-bdb7-4d10858c27b2")! let wrapped = UUIDv1(rawValue: raw) ``` -------------------------------- ### UUID.v5() — Generate a name-based UUID using SHA-1 Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a deterministic version 5 UUID by hashing a namespace UUID and a name with SHA-1. This is the recommended name-based UUID variant for new applications. Identical inputs always produce the same UUID. ```APIDOC ## UUID.v5() ### Description Generates a deterministic version 5 UUID by hashing a namespace UUID and a name with SHA-1. This is the recommended name-based UUID variant for new applications. Identical inputs always produce the same UUID. ### Usage ```swift import UUIDKit // Standard namespaces: .dns, .url, .oid, .x500 let uuid = UUID.v5(name: "test.test", namespace: .dns) // Always produces: "783D51C2-94CD-5E7A-8AFE-C2FD6D91F7A2" let urlUUID = UUID.v5(name: "http://example.com/index.html", namespace: .url) let oidUUID = UUID.v5(name: "1.2.3.4.5", namespace: .oid) // Custom namespace from any UUID let customNS = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) let custom = UUID.v5(name: "my-resource", namespace: customNS) // Works with Data and [UInt8] too import Foundation let data = Data([0x68, 0x65, 0x6c, 0x6c, 0x6f]) let fromData = UUID.v5(name: data, namespace: .url) // Typed wrapper let typed = UUIDv5("783d51c2-94cd-5e7a-8afe-c2fd6d91f7a2") let invalid = UUIDv5("712869ea-f10f-40b7-b192-4f8653973806") // nil — not v5 ``` ``` -------------------------------- ### Generate Random UUID (v4) Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a version 4 UUID using the system's random number generator. A custom `RandomNumberGenerator` can be provided for deterministic output, useful in testing scenarios. Typed wrappers can parse and validate existing UUIDs, returning nil if the version does not match. ```swift import UUIDKit // Default system-random UUID let uuid = UUID.v4() // e.g. "712869EA-F10F-40B7-B192-4F8653973806" // With a custom random number generator (useful for testing) var generator = SystemRandomNumberGenerator() let deterministicUUID = UUID.v4(using: &generator) // Typed wrapper usage let typed = UUIDv4() print(typed.rawValue.version) // Parse/wrap existing UUIDs — returns nil if version != 4 let fromString = UUIDv4("712869ea-f10f-40b7-b192-4f8653973806") let fromRaw = UUIDv4(rawValue: UUID(uuidString: "712869ea-f10f-40b7-b192-4f8653973806")!) let invalid = UUIDv4("d2989d1a-3bf9-11ec-bdb7-4d10858c27b2") // nil — v1 UUID rejected ``` -------------------------------- ### Define Namespaces for Name-Based UUIDs Source: https://context7.com/baarde/uuid-kit/llms.txt UUID.Namespace is a strongly-typed wrapper around UUID for generating v3 or v5 UUIDs. Supports pre-defined RFC 4122 namespaces and custom namespaces from any UUID or string. Can be used as a Hashable key. ```swift import UUIDKit // Pre-defined RFC 4122 namespaces let dns = UUID.Namespace.dns // 6BA7B810-9DAD-11D1-80B4-00C04FD430C8 let url = UUID.Namespace.url // 6BA7B811-9DAD-11D1-80B4-00C04FD430C8 let oid = UUID.Namespace.oid // 6BA7B812-9DAD-11D1-80B4-00C04FD430C8 let x500 = UUID.Namespace.x500 // 6BA7B814-9DAD-11D1-80B4-00C04FD430C8 // Custom namespace from a UUID literal let custom = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) // From a string (LosslessStringConvertible) let fromString = UUID.Namespace("6ba7b810-9dad-11d1-80b4-00c04fd430c8") // Codable — encode/decode namespace in JSON import Foundation let encoded = try JSONEncoder().encode(dns) let decoded = try JSONDecoder().decode(UUID.Namespace.self, from: encoded) // Use as a Hashable key in a dictionary var registry: [UUID.Namespace: String] = [ .dns: "Domain Name System", .url: "Uniform Resource Locator", ] ``` -------------------------------- ### UUID.Namespace — Define namespaces for name-based UUIDs Source: https://context7.com/baarde/uuid-kit/llms.txt `UUID.Namespace` is a strongly-typed wrapper around `UUID` used as a prefix when generating v3 or v5 UUIDs. It ships with the four RFC 4122 pre-defined namespaces and supports constructing custom namespaces from any `UUID`. ```APIDOC ## UUID.Namespace ### Description `UUID.Namespace` is a strongly-typed wrapper around `UUID` used as a prefix when generating v3 or v5 UUIDs. It ships with the four RFC 4122 pre-defined namespaces and supports constructing custom namespaces from any `UUID`. ### Usage ```swift import UUIDKit // Pre-defined RFC 4122 namespaces let dns = UUID.Namespace.dns // 6BA7B810-9DAD-11D1-80B4-00C04FD430C8 let url = UUID.Namespace.url // 6BA7B811-9DAD-11D1-80B4-00C04FD430C8 let oid = UUID.Namespace.oid // 6BA7B812-9DAD-11D1-80B4-00C04FD430C8 let x500 = UUID.Namespace.x500 // 6BA7B814-9DAD-11D1-80B4-00C04FD430C8 // Custom namespace from a UUID literal let custom = UUID.Namespace(UUID(uuidString: "34cd6bf4-3f41-4717-95ea-131762f60af8")!) // From a string (LosslessStringConvertible) let fromString = UUID.Namespace("6ba7b810-9dad-11d1-80b4-00c04fd430c8") // Codable — encode/decode namespace in JSON import Foundation let encoded = try JSONEncoder().encode(dns) let decoded = try JSONDecoder().decode(UUID.Namespace.self, from: encoded) // Use as a Hashable key in a dictionary var registry: [UUID.Namespace: String] = [ .dns: "Domain Name System", .url: "Uniform Resource Locator", ] ``` ``` -------------------------------- ### UUID.v1() — Generate a time-based UUID Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a version 1 UUID based on the current system time and a randomly generated node identifier. The node identifier is generated once per process run and is constant for all v1 UUIDs created in that session, ensuring monotonicity without leaking MAC address information. ```APIDOC ## UUID.v1() ### Description Generates a version 1 UUID based on the current system time and a randomly generated node identifier. The node identifier is generated once per process run and is constant for all v1 UUIDs created in that session, ensuring monotonicity without leaking MAC address information. ### Usage ```swift import UUIDKit // Simple time-based UUID generation let uuid = UUID.v1() // e.g. "D2989D1A-3BF9-11EC-BDB7-4D10858C27B2" // Using the typed wrapper for full field access let typed = UUIDv1() print(typed.rawValue) print(typed.timestamp.rawValue) print(typed.clockSequence.rawValue) print(typed.node.rawValue) // Parse an existing v1 UUID string (returns nil if not v1) let parsed = UUIDv1("d2989d1a-3bf9-11ec-bdb7-4d10858c27b2") // Use RawRepresentable init to wrap an existing Foundation UUID let raw = UUID(uuidString: "d2989d1a-3bf9-11ec-bdb7-4d10858c27b2")! let wrapped = UUIDv1(rawValue: raw) ``` ``` -------------------------------- ### UUID.variant and UUID.version — Inspect UUID metadata Source: https://context7.com/baarde/uuid-kit/llms.txt Extensions on Foundation's `UUID` type that expose the RFC 4122 variant field and version number, enabling runtime inspection of any UUID's structure. ```APIDOC ## UUID.variant and UUID.version ### Description Extensions on Foundation's `UUID` type that expose the RFC 4122 variant field and version number, enabling runtime inspection of any UUID's structure. ### Usage ```swift import UUIDKit // Inspect a standard RFC 4122 UUID let uuid = UUID(uuidString: "712869EA-F10F-40B7-B192-4F8653973806")! uuid.variant // .rfc4122 uuid.version // Optional(4) // The null UUID (all zeros) UUID.null.variant // .reservedNCS UUID.null.version // nil // Non-RFC-4122 variants return nil for version let ms = UUID(uuidString: "00000131-0000-0000-c000-000000000046")! ms.variant // .reservedMicrosoft ms.version // nil let future = UUID(uuidString: "ffffffff-ffff-ffff-ffff-ffffffffffff")! future.variant // .reservedFuture future.version // nil // Check version at runtime before using typed wrapper let unknown = UUID() // random v4 from Foundation if unknown.variant == .rfc4122, unknown.version == 1 { let v1 = UUIDv1(rawValue: unknown) } ``` ``` -------------------------------- ### Work with v1 UUID Timestamps Source: https://context7.com/baarde/uuid-kit/llms.txt UUIDv1.Timestamp encodes the 60-bit RFC 4122 timestamp. It is Comparable and inter-converts with Swift Date. Supports creation from Date and comparison for ordering. ```swift import UUIDKit import Foundation // Extract timestamp from a v1 UUID and convert to Date let typed = UUIDv1("d2989d1a-3bf9-11ec-bdb7-4d10858c27b2")! let ts = typed.timestamp let date = Date(ts) // Converts back to Swift Date // Create a timestamp from a Date let now = UUIDv1.Timestamp(Date()) let epoch1970 = UUIDv1.Timestamp(secondsSince1970: 0, nanoseconds: 0) // Compare timestamps for ordering let a = UUIDv1() let b = UUIDv1() assert(a.timestamp < b.timestamp) // monotonically increasing // Boundary values let minTS = UUIDv1.Timestamp.min // == .zero let maxTS = UUIDv1.Timestamp.max ``` -------------------------------- ### Generate Time-based UUID (v1) in Swift Source: https://github.com/baarde/uuid-kit/blob/main/README.md Creates a version 1 UUID using a random node identifier for program execution duration, as per RFC 4122 section 4.5. ```swift let uuidv1 = UUID.v1() ``` -------------------------------- ### Generate Random UUID (v4) in Swift Source: https://github.com/baarde/uuid-kit/blob/main/README.md Generates a version 4 UUID using a system random number generator. A custom generator can be provided. ```swift var generator = SystemRandomNumberGenerator() let uuidv4 = UUID.v4(using: generator) ``` -------------------------------- ### UUIDv1.Timestamp — Work with v1 UUID timestamps Source: https://context7.com/baarde/uuid-kit/llms.txt `UUIDv1.Timestamp` encodes the 60-bit RFC 4122 timestamp (100-nanosecond intervals since October 15, 1582). It is `Comparable` and inter-converts with Swift `Date`. ```APIDOC ## UUIDv1.Timestamp ### Description `UUIDv1.Timestamp` encodes the 60-bit RFC 4122 timestamp (100-nanosecond intervals since October 15, 1582). It is `Comparable` and inter-converts with Swift `Date`. ### Usage ```swift import UUIDKit import Foundation // Extract timestamp from a v1 UUID and convert to Date let typed = UUIDv1("d2989d1a-3bf9-11ec-bdb7-4d10858c27b2")! let ts = typed.timestamp let date = Date(ts) // Converts back to Swift Date // Create a timestamp from a Date let now = UUIDv1.Timestamp(Date()) let epoch1970 = UUIDv1.Timestamp(secondsSince1970: 0, nanoseconds: 0) // Compare timestamps for ordering let a = UUIDv1() let b = UUIDv1() assert(a.timestamp < b.timestamp) // monotonically increasing // Boundary values let minTS = UUIDv1.Timestamp.min // == .zero let maxTS = UUIDv1.Timestamp.max ``` ``` -------------------------------- ### UUID.v4() — Generate a random UUID Source: https://context7.com/baarde/uuid-kit/llms.txt Generates a version 4 UUID using the system's default random number generator, or a custom `RandomNumberGenerator` for deterministic/testable output. ```APIDOC ## UUID.v4() ### Description Generates a version 4 UUID using the system's default random number generator, or a custom `RandomNumberGenerator` for deterministic/testable output. ### Usage ```swift import UUIDKit // Default system-random UUID let uuid = UUID.v4() // e.g. "712869EA-F10F-40B7-B192-4F8653973806" // With a custom random number generator (useful for testing) var generator = SystemRandomNumberGenerator() let deterministicUUID = UUID.v4(using: &generator) // Typed wrapper usage let typed = UUIDv4() print(typed.rawValue.version) // Parse/wrap existing UUIDs — returns nil if version != 4 let fromString = UUIDv4("712869ea-f10f-40b7-b192-4f8653973806") let fromRaw = UUIDv4(rawValue: UUID(uuidString: "712869ea-f10f-40b7-b192-4f8653973806")!) let invalid = UUIDv4("d2989d1a-3bf9-11ec-bdb7-4d10858c27b2") // nil — v1 UUID rejected ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.