Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hexadecimal string from NSDate
import Foundation
extension NSData {
var hexadecimalString: String {
var result = ""
enumerateByteRangesUsingBlock { (pointer, range, _) in
let pointerToBytes = UnsafePointer<UInt8>(pointer)
let bytes = UnsafeBufferPointer(start: pointerToBytes, count: range.length)
for v in bytes {
result.appendContentsOf(String(format:"%02x", v))
}
}
return result
}
}
let d = NSData(bytes: [0xDE, 0xAD, 0xBE, 0xEF] as [UInt8], length: 4)
let c = d.hexadecimalString // deadbeef
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.