Try this one:

let uuid = NSUUID().uuidString
print(uuid)

Swift 3/4/5

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

You could also just use the NSUUID API:

let uuid = NSUUID()

If you want to get the string value back out, you can use uuid.UUIDString.

Note that NSUUID is available from iOS 6 and up.


For Swift 4;

let uuid = NSUUID().uuidString.lowercased()

For Swift 3, many Foundation types have dropped the 'NS' prefix, so you'd access it by UUID().uuidString.