Muhammad Usman Piracha Muhammad Usman Piracha - 4 months ago 35
iOS Question

Reading \n in UiLabel

I am assigning value to

. If I get value from
than \n shows as it is and doesn't read it as new line.
Here is my code

let cards:Card = cardArray[0] as! Card
lblTitle?.text = cards.title
//Output in UiLabel is "This is \n title"

I want UiLabel to read \n as new line

However below code gives expected output

lblTitle?.text = "This is \n title"


I think you title contains escaped character i.e the reason \n is printing try once replacing \\n with \n.

Swift 3

lblTitle?.text = cards.title.replacingOccurrences(of: "\\n", with: "\n")

Swifr 2.3 or lower

lblTitle?.text = cards.title.stringByReplacingOccurrencesOfString("\\n", withString: "\n")