Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Foundation
extension Data {
var hexString1: String {
return self.map({ return String(format: "%02hhx", $0) }).joined()
}
var hexString2: String {
return self.reduce("", { return $0 + String(format: "%02hhx", $1) })
}
var hexString3: String {
return self.reduce("", { String(format: "\($0)%02hhx", $1) })
}
}
let token = "test data".data(using: String.Encoding.utf8)!
token.hexString3 == "746573742064617461" // => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment