Skip to content

Instantly share code, notes, and snippets.

@deathslocus
Created January 6, 2017 08:58
Show Gist options
  • Save deathslocus/6b4e40f1bf65400c535ed43b20e634b9 to your computer and use it in GitHub Desktop.
Save deathslocus/6b4e40f1bf65400c535ed43b20e634b9 to your computer and use it in GitHub Desktop.
Utility for creating version 3 UUID from name
func nameUUIDFromBytes(name: String) -> NSUUID{
let nameBytes = name.data(using: .utf8)
var digest : Data = (nameBytes?.md5())!
digest[6] &= 0x0F
digest[6] |= 0x30
digest[8] &= 0x3F
digest[8] |= 0x80
var arr : [UInt8] = []
for i in digest {
arr.append(i)
}
return NSUUID(uuidBytes: arr)
}
@deathslocus
Copy link
Author

I should note you need CryptoSwift for this to work https://github.com/krzyzanowskim/CryptoSwift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment