Skip to content

Instantly share code, notes, and snippets.

@wess
Created June 17, 2016 16:38
Show Gist options
  • Select an option

  • Save wess/b371e0eb68a7fe326e5abde696d51d23 to your computer and use it in GitHub Desktop.

Select an option

Save wess/b371e0eb68a7fe326e5abde696d51d23 to your computer and use it in GitHub Desktop.
private func stringFromHexString(string:String) -> String? {
guard (string.length % 2) != 0 else { return nil }
var hex = string
var result = ""
while(hex.length > 0) {
let advance = hex.startIndex.advancedBy(2)
let substring = hex.substringToIndex(advance)
hex = hex.substringFromIndex(advance)
var char:UInt32 = 0
NSScanner(string: substring).scanHexInt(&char)
result = result.stringByAppendingString(String(format:"%c", char))
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment