Skip to content

Instantly share code, notes, and snippets.

@NikolaiRuhe
Last active June 3, 2016 07:28
Show Gist options
  • Save NikolaiRuhe/9f402a056953624fdd6a0f6529b04b91 to your computer and use it in GitHub Desktop.
Save NikolaiRuhe/9f402a056953624fdd6a0f6529b04b91 to your computer and use it in GitHub Desktop.
extension CBUUID {
func representativeString() -> String {
let data = self.data
let buffer = UnsafeBufferPointer<UInt8>(start: UnsafePointer(data.bytes), count: data.length)
let hex: (UInt8) -> String = { ($0 <= 9 ? "0" : "") + String($0, radix: 16, uppercase: true) }
let dashInserter: (Int) -> String = { [3, 5, 7, 9].contains($0) ? "-" : "" }
return buffer.map(hex)
.enumerate()
.reduce("") {
$0 + dashInserter($1.0) + $1.1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment