Generate a UUID on iOS from Swift Generate a UUID on iOS from Swift swift swift

Generate a UUID on iOS from Swift


Try this one:

let uuid = NSUUID().uuidStringprint(uuid)

Swift 3/4/5

let uuid = UUID().uuidStringprint(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()