How to Generate UUIDs in Objective-C

Generate UUIDs in Objective-C with NSUUID for native random v4 values. If you need UUID v7 on Apple platforms, use a third-party RFC 9562-compatible library because Foundation does not expose it directly.

Recommendation: use native NSUUID for portable random identifiers, and only add UUID v7 through a vetted library when time ordering is a real requirement.

How to generate UUID v4 in Objective-C

NSUUID *uuid = [[NSUUID alloc] init];
NSString *value = uuid.UUIDString;

NSLog(@"%@", value);

How to generate UUID v7 in Objective-C

Foundation does not provide native UUID v7 generation in Objective-C. Use a vetted third-party library that explicitly documents RFC 9562 UUID v7 support if your project needs sortable UUIDs.

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

Native support notes

  • Objective-C typically uses UUID terminology through Foundation's NSUUID type.
  • [[NSUUID alloc] init] creates RFC 4122 version 4 random bytes.
  • UUID v7 is not part of the standard Apple Foundation API surface.

Practical notes

  • Use native UUID v4 for local identifiers, persistence, and cross-platform interoperability.
  • Keep UUID v7 generation in one library boundary if you add it to an older Objective-C codebase.
  • Bridge UUID strings carefully if your Objective-C app exchanges identifiers with Swift code.

Frequently Asked Questions

Yes. Foundation provides NSUUID, which is the normal native API for random UUID generation.

NSUUID generates random RFC 4122 version 4 UUID values, not time-ordered UUID v7 values.

No. UUID v7 requires a third-party library because Foundation does not expose a native Objective-C 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.