Skip to content

Instantly share code, notes, and snippets.

@jurezove
Created December 15, 2015 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jurezove/8ae32205ca939298eeac to your computer and use it in GitHub Desktop.
Save jurezove/8ae32205ca939298eeac to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
import Foundation
extension NSString {
private static let unicodeTransform: NSString = "Any-Hex/Java"
func decodeUnicode() -> NSString? {
if let decoded = self.mutableCopy() as? NSMutableString {
CFStringTransform(decoded, nil, String.unicodeTransform, true)
return decoded
}
//TODO warning
return nil
}
func encodeUnicode() -> NSString {
//TODO
return self
}
}
if let file = NSBundle.mainBundle().pathForResource("test3", ofType: "json") {
do {
let content = try NSString(contentsOfFile: file, encoding: NSUTF8StringEncoding)
if let data = content.dataUsingEncoding(NSUnicodeStringEncoding) {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
if let tips = json["tips"],
home_screen = tips!["home_screen"],
html_content = home_screen!["html_content"] as? NSString {
let s = html_content.decodeUnicode()
}
}
} catch {
print(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment