Skip to content

Instantly share code, notes, and snippets.

@vincent-peng
Last active November 26, 2023 14:28
Show Gist options
  • Save vincent-peng/07897b760c9e27573957a4cf7d10b5ee to your computer and use it in GitHub Desktop.
Save vincent-peng/07897b760c9e27573957a4cf7d10b5ee to your computer and use it in GitHub Desktop.
Convert Data to hex string in Swift
// http://stackoverflow.com/a/40089462
extension Data {
func hexEncodedString() -> String {
return map { String(format: "%02hhx", $0) }.joined()
}
}
@osfunapps
Copy link

great!

@movilesnetcom
Copy link

Niceeee, thanks!

@iErich
Copy link

iErich commented Sep 25, 2019

you saved my day big time - THANK YOU

@jdmuys
Copy link

jdmuys commented Nov 8, 2019

Very good.
Any quick way to do the reverse, ie to create a Data from a hex-encoded string?

@yerzhant
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment