- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Swift 制作应用程序,并且正在使用 Firebase Firestore。 Firestore 是一个数据库,其中包含一些我放入 UILabel
中的字符串。对于我的一些字符串,我正在使用换行命令(或 \n)
。所以我的一些字符串看起来像这样:
"This is line one\nThis is line two\nThis is line three"
但是,无论何时检索到该字符串,它都会添加到 UILabel
中并显示如下...
这是第一行\n这是第二行\n这是第三行
……什么时候应该是这样的……
这是第一行
这是第二行
这是第三行
我假设 \n
不适用于来自数据库的字符串?我试过使用 \\n
进行双重转义。有人对此有解决办法吗?
这是我正在使用的代码...
database.collection("songs").whereField("storyTitle", isEqualTo: "This is the story header").getDocuments { (snapshot, error) in
for document in (snapshot?.documents)! {
self.storyBodyLabel.text = (document.data()["storyBody"] as? String)!
}
}
最佳答案
我明白了。我只是用换行命令替换了我收到的字符串中的字符“\n”。
label.text = stringRecived.replacingOccurrences(of: "\n", with: "\n")
因为我手动输入了我的字符串并给了 Firebase 一个像这样的字符串“第一行\n第二行\n第三行”
我将“\n”替换为“\n”但是如果你给 Firebase 一个像这样的字符串
"Line one
Line two
Line three"
Firebase 将这些返回替换为 "\\n"
从而生成代码
label.text = stringRecived.replacingOccurrences(of: "\\n", with: "\n")
希望对您有所帮助!
关于swift - 换行命令 (\n) 不适用于 Firebase Firestore 数据库字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48755746/
我是一名优秀的程序员,十分优秀!