New Line Command (\n) Not Working With Firebase Firestore Database Strings

I got it. I simply just replaced the character "\n" from the string that I was receiving with the newline command.

label.text = stringRecived.replacingOccurrences(of: "\n", with: "\n")

Because I manually typed out my string and gave Firebase a string like "Line one\nline two\nline three" I am replacing "\n" with "\n" But if you give Firebase a string like

"Line one
Line two
Line three"

Firebase replaces those returns with "\\n" therfore making the code

label.text = stringRecived.replacingOccurrences(of: "\\n", with: "\n")

Hope that helps!


Firestore doesn't support any escape sequences within string values. If you write "\n" in a string, you're going to get exactly that back when you read it. If you need to store something special, you may want to encode and decode that yourself.


You can use CSS whitespace property for \n, it works for me.

white-space: pre-line;