Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.