Created
November 15, 2016 16:16
-
-
Save khanlou/d248402a8fd960304b96db87b062ed7e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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