Last active
June 3, 2016 07:28
-
-
Save NikolaiRuhe/9f402a056953624fdd6a0f6529b04b91 to your computer and use it in GitHub Desktop.
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 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