UUID in Swift

Swift UUID Generator

Swift hands you a v4 UUID in one line, but the string comes back uppercase — a difference that breaks exact-match comparisons against values from anywhere else.

Foundationv4 built inUppercase by default

Generated locally with the Web Crypto API — nothing leaves your browser.

Generating UUIDs in Swift

How to generate

  1. Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
  2. Copy one value with Copy, or set How many and use Copy all for a fixture list.
  3. Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.

Use Cases

How Swift UUID Generator Compares

UUID().uuidStringv4, uppercase, from Foundation
UUID().uuidThe 16-byte value itself, for binary storage
uuidString.lowercased()The form to use when comparing with other services

Code Examples

Swift
import Foundation

let id = UUID()
print(id.uuidString)              // "8F2C7B41-0D3E-4A55-B6C1-8E7D9F0A1B2C"
print(id.uuidString.lowercased()) // normalised, matches other languages

// Ready for Codable / JSON
struct Order: Codable {
    let id: String = UUID().uuidString.lowercased()
}
Storage
// 16 raw bytes when the column is binary, not a string
let bytes = withUnsafeBytes(of: id.uuid) { Data($0) }   // 16 bytes
let back = UUID(uuid: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))

Frequently Asked Questions

Why is Swift's uuidString uppercase?
Foundation renders the hex in uppercase. It is still a valid UUID — hex digits are case-insensitive per RFC 9562 — but lowercase it before comparing with values produced elsewhere.
How do I generate a UUID v7 in Swift?
There is no standard-library v7. Use a v7 package, or have the server generate the identifier and treat it as an opaque string on the client.
How much space does a UUID take in Swift?
16 bytes as the UUID value or Data, and 36 characters as the hyphenated string — worth remembering before storing the string form in a large table.

Related tools