0

I am sending data via socket.io my app, which I want to embed the text of a parameter in a UILabel

Javascript server

socket.emit("app",{ac:"organización"})

iOS App

var ac = self.jsonOFsocket["ac"] as String
//ac === "organización"
self.label.text = ac
//self.label.text === "organizaci\U00f3n"
  1. The socket.io the app sends unencrypted characters.
  2. The app successfully receives all characters
  3. The app shows different symbols

I try to do this:

func utf(txt:String) -> NSString {
   var newTxt = NSString(format:txt, NSUTF8StringEncoding)
   newTxt.precomposedStringWithCanonicalMapping
   return newTxt
}

var ac = self.jsonOFsocket["ac"] as String
//ac === "organización"
self.label.text = uft(ac)
//self.label.text === "organizaciââ¥n"

This is important:

organizaciââ¥n
0

1 Answer 1

1

This is the Objective-C way:

NSData *data = [MyString dataUsingEncoding:NSUTF8StringEncoding];
NSString *stringWithSpecialCharacters = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];

You'll have to store the proper string format on your server too and make sure it returns the right string via curl.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it has served me well !! var ns = NSString(string: "poblaci\\U00f3n") var data:NSData = ns.dataUsingEncoding(NSUTF8StringEncoding)! var sc = NSString(data:data,encoding:NSNonLossyASCIIStringEncoding)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.