Created
June 17, 2016 16:38
-
-
Save wess/b371e0eb68a7fe326e5abde696d51d23 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
| 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