gpt4 book ai didi

ios - 根据(城市)从 firebase 检索数据

转载 作者:行者123 更新时间:2023-11-28 08:40:54 25 4
gpt4 key购买 nike

我正在使用 swift 开发 iOS 应用程序,我在应用程序的 firebase 仪表板中有以下数据

Users =     
{
"07a5fa11-2a09-455b-92bf-a86dcd9d3e3e" =
{
Name = "Hissah";
Category = "Art & Designe";
City = "Riyadh";
Email = "H@him.fm";
ShortDescription = "";
};
"08e5443c-cdde-4fda-8733-8c4fce75dd34" =
{
Name = "Sara";
Category = "Cheefs";
City = "Dubai";
Email = "Sara@gmail.com";
ShortDescription = "best cake ever . ";
};

如何将(城市)为“Riyadh”的用户的(姓名)检索到 TableView 中?

提前致谢。

最佳答案

把这个扔进圈子里,因为它是一个简单的答案,并解决了一个可用于填充 tableView 的数据源

let ref = Firebase(url:"https://your-app.firebaseio.com/users")

ref.queryOrderedByChild("City").queryEqualToValue("Riyadh")
.observeEventType(.Value, withBlock: { snapshot in

//iterate over all the values read in and add each name
// to an array
for child in snapshot.children {
let name = child.value["Name"] as! NSString
self.tableViewDataSourceArray.append(name)
}

//the tableView uses the tableViewDataSourceArray
// as it's dataSource
self.tableView.reloadData()

})

编辑:后续评论询问如何将文本添加到 NSTextView

ref.queryOrderedByChild("City").queryEqualToValue("Riyadh")
.observeEventType(.Value, withBlock: { snapshot in

//iterate over all the values and add them to a string
var s = String()
for child in snapshot.children {
let name = child.value["Name"] as! NSString
s += name + "\n" // the \n puts each name on a line
}

//add the string we just build to a textView
let attrString = NSAttributedString(string: s)
self.myTextView.textStorage?.appendAttributedString(attrString)

})

关于ios - 根据(城市)从 firebase 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36508450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com