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

后端 未结 6 997
天涯浪人
天涯浪人 2020-12-06 01:36

I\'m making an app with Swift and I\'m using Firebase Firestore. Firestore is a database that has some strings that I put into a UILabel. With some of my stings

6条回答
  •  情歌与酒
    2020-12-06 02:18

    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 sting 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!

提交回复
热议问题