iOS Developer Library

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. More...

Inheritance


Import Statement


import Foundation @import Foundation;

Availability


Available in iOS 6.0 and later.
  • Create and returns a new UUID with RFC 4122 version 4 random bytes.

    Declaration

    Objective-C

    + (instancetype)UUID

    Return Value

    A new UUID object.

    Import Statement

    Availability

    Available in iOS 6.0 and later.

  • init() init Designated Initializer

    Create and returns a new UUID with RFC 4122 version 4 random bytes.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    A new UUID object.

    Import Statement

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Creates and returns a new UUID with the given bytes.

    Declaration

    Swift

    convenience init(UUIDBytes bytes: UnsafePointer<UInt8>)

    Objective-C

    - (instancetype)initWithUUIDBytes:(const uuid_t)bytes

    Parameters

    bytes

    Raw UUID bytes to use to create the UUID.

    Return Value

    A new UUID object.

    Import Statement

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Creates and returns a new UUID from the formatted string.

    Declaration

    Swift

    convenience init?(UUIDString string: String)

    Objective-C

    - (instancetype)initWithUUIDString:(NSString *)string

    Parameters

    string

    The source string containing the UUID. The standard format for UUIDs represented in ASCII is a string punctuated by hyphens, for example 68753A44-4D6F-1226-9C60-0050E4C00067.

    Return Value

    A new UUID object. Returns nil for invalid strings.

    Import Statement

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • 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.

    Import Statement

    import Foundation

    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) 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.

    Import Statement

    import Foundation

    Availability

    Available in iOS 6.0 and later.