How to Generate UUIDs in Swift

Generate UUIDs in Swift with Foundation's UUID() for native random v4 values. If your app needs UUID v7, use a third-party RFC 9562-compatible package because the standard Foundation API does not expose it directly.

Recommendation: use native Foundation UUIDs for simple app and model identifiers, and only add UUID v7 through a package when ordered IDs materially help your storage or sync flows.

How to generate UUID v4 in Swift

let id = UUID()
print(id.uuidString)

How to generate UUID v7 in Swift

Swift Foundation does not provide native UUID v7 generation. Use a third-party package that explicitly documents RFC 9562 UUID v7 support if you need sortable UUID values.

// Foundation does not expose native UUID v7 generation.
// Use a third-party RFC 9562-compatible package when UUID v7 is required.

Native support notes

  • Swift uses UUID terminology through Foundation's UUID type.
  • UUID() creates RFC 4122 version 4 random bytes.
  • UUID v7 is not part of the standard Swift Foundation API surface.

Practical notes

  • Use native UUID v4 for app state, local persistence, and network payload identifiers.
  • Adopt one UUID v7 package consistently if Swift and backend code must sort by creation time.
  • Keep string formatting consistent if your app exchanges UUIDs with Objective-C or server APIs.

Frequently Asked Questions

Yes. Foundation provides UUID(), which is the standard native API for random UUID generation in Swift.

Yes. Apple's Foundation documentation states that UUID() creates RFC 4122 version 4 random bytes.

No. UUID v7 requires a third-party package because Foundation does not expose a native Swift API for it.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.