0
后取回呢?这里是我的代码:操作数据从火力地堡
//从火力地堡
func getData(withBlock completion:@escaping() ->Void){
let ref = Database.database().reference().child("hobbies")
let query = ref.queryOrdered(byChild: "cost").queryEqual(toValue: "low")
query.observe(.childAdded, with: {(snapshot) in
self.user_choice_Cost.append((snapshot.childSnapshot(forPath: "hobbyName").value as? String)!)
completion()
//print(self.user_choice_Cost)
})
{ (error) in
print(error)
}
获取数据
//处理数据
getData{
let set2:Set<String> = ["a"]
let set1:Set<String> = Set(self.user_choice_Cost)
print(set1.union(set2))}
这工作正常!但是没有什么办法可与所有值(“A”,“B”])得到user_choice_Cost而不是一个接一个地([“一”],[“一”,“B”)]和操纵user_choice_Cost阵列不用把它放在里面getData {}。因为如果我把外面只会返回“A”
你为什么不为您的数据建立模型类? –
这只是一个快速草案。如果我创建模型类更好吗?它会解决一个接一个的价值吗? –