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
UUID()makes a version 4 value using the system's random source, and.uuidStringrenders it as uppercase —8F2C7B41-0D3E-4A55-B6C1-8E7D9F0A1B2C. That is valid RFC 9562, since hex case is not significant, but it is a real trap: a lowercase UUID stored by another service will not compare equal as a string. Normalise with.lowercased()at the boundary.- Swift has no built-in v7. If you need time-ordered keys — for SwiftData, CloudKit or a server-side Swift service — use a package such as
swift-uuid, or generate in the backend and keep the client unaware of the version.
How to generate
- Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
- Copy one value with Copy, or set How many and use Copy all for a fixture list.
- Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.
Use Cases
- SwiftData and Core Data keys — an identifier that does not need a round trip to the server.
- Offline-first records — the device can mint the ID and sync later without collisions.
- Analytics and logging correlation, one value per session or per request.
How Swift UUID Generator Compares
| UUID().uuidString | v4, uppercase, from Foundation |
| UUID().uuid | The 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
UUID v1 GeneratorUUID v3 GeneratorUUID v4 GeneratorUUID v5 GeneratorUUID v6 GeneratorUUID v7 GeneratorUUID v8 GeneratorBulk UUID GeneratorShort UUID GeneratorUUID ValidatorUUID FormatterJavaScript UUID GeneratorTypeScript UUID GeneratorNode.js UUID GeneratorReact UUID GeneratorPython UUID GeneratorJava UUID GeneratorC# UUID GeneratorGo UUID GeneratorPHP UUID GeneratorRuby UUID GeneratorRust UUID GeneratorKotlin UUID GeneratorSwift UUID GeneratorSQL UUID Generator