Generate a UUID on iOS from Swift

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

In my iOS Swift app I want to generate random UUID ( GUID ) strings for use as a table key, and this snippet appears to work:

let uuid = CFUUIDCreateString(nil, CFUUIDCreate(nil))

Is this safe?

Or is there perhaps a better (recommended) approach?

Answers

Try this one:

let uuid = NSUUID().UUIDString
print(uuid)
  Swift 3   
let uuid = UUID().uuidString
print(uuid)

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/24428250/generate-a-uuid-on-ios-from-swift

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils