iOS Developer Library — Prerelease

Developer

Foundation Framework Reference NSUUID Class Reference

Options
Deployment Target:

On This Page
Language:

NSUUID

The NSUUID class creates UUID strings that are to uniquely identify types, interfaces, and other items.

UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs (Interface Identifiers), are 128-bit values. UUIDs created by NSUUID conform to RFC 4122 version 4 and are created with random bytes.

The standard format for UUIDs represented in ASCII is a string punctuated by hyphens, for example 68753A44-4D6F-1226-9C60-0050E4C00067. The hex representation looks, as you might expect, like a list of numerical values preceded by 0x. For example, 0xD7, 0x36, 0x95, 0x0A, 0x4D, 0x6E, 0x12, 0x26, 0x80, 0x3A, 0x00, 0x50, 0xE4, 0xC0, 0x00, 0x67. Because a UUID is expressed simply as an array of bytes, there are no endianness considerations for different platforms.

  • Returns the UUIDs bytes.

    Declaration

    Swift

    func getUUIDBytes(_ uuid: UnsafeMutablePointer<UInt8>)

    Objective-C

    - (void)getUUIDBytes:(uuid_t)uuid

    Parameters

    uuid

    The value of uuid represented as raw bytes.

    Availability

    Available in iOS 6.0 and later.

  • The UUID as a string. (read-only)

    Declaration

    Swift

    var UUIDString: String { get }

    Objective-C

    @property(readonly, copy, nonnull) NSString *UUIDString

    Discussion

    A string containing a formatted UUID for example E621E1F8-C36C-495A-93FC-0C247A3E6E5F.

    Use this property when you need a string representation of the NSUUID object—for example, to compare with a CFUUIDRef object.

    Availability

    Available in iOS 6.0 and later.