Last active
September 7, 2015 06:09
-
-
Save chuganzy/85743eee8609a80dd35a to your computer and use it in GitHub Desktop.
uuid_generate_time in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSUUID { | |
class func timeBasedUUID() -> NSUUID { | |
let uuidSize = sizeof(uuid_t) | |
let uuidPointer = UnsafeMutablePointer<UInt8>.alloc(uuidSize) | |
uuid_generate_time(uuidPointer) | |
let uuid = NSUUID(UUIDBytes: uuidPointer) | |
uuidPointer.dealloc(uuidSize) | |
return uuid | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment