0

I would like to set some unicode strings (for a custom font icon).

Like:

cell.centerIconLabel.text = "\u{f013}"

But when i now read some variables from a webservice, how can i convert this to an unicode string?

If the webservice returns me "\u{f013}" and i set this as string, it will show only the string (and not the icon).

// not working

cell.centerIconLabel.text = item.icon // which contains "\u{f013}"

Any ideas?

Edit:

Thanks Martin, that was the answer i was looking for. Maybe add as answer here too (was unable to find it on Stackoverflow).

let code = 0xf013
cell.centerIconLabel.text = String(UnicodeScalar(code))
derdida
  • 14,784
  • 16
  • 90
  • 139
  • 1
    How do you read the string from the web service? Why can the web service not send Unicode characters without escaping them with `\u{}`? JSON for example supports arbitrary unicode characters. – Martin R Sep 06 '16 at 11:35
  • But how can i set a variable then? How can i say Swift that this is a unicode string (otherwise it will display me f013.) – derdida Sep 06 '16 at 11:37
  • 2
    Perhaps this is what you are looking for: [Print unicode character from variable (swift)](http://stackoverflow.com/questions/31696142/print-unicode-character-from-variable-swift). – Martin R Sep 06 '16 at 11:40
  • use attribute text with this may fix issue – Shobhakar Tiwari Sep 06 '16 at 11:40

0 Answers0