【发布时间】:2016-08-19 08:27:42
【问题描述】:
我试图用不同的标签对字典的每个项目进行排序(在我的例子中:firebase 中的投票进入指定的“votelabel”,“textlabel”中的文本......),我试图这样做但我真的有货。我认为我的问题是因为每个帖子都有一个新密钥,我不知道如何直接给孩子们
var posts: [String: AnyObject] = [String: AnyObject]()
@IBAction func save(sender: AnyObject) {
let titre = Titre.text
let soustitre = SousTitre.text
let text = Text.text
let newPosts: Dictionary<String, AnyObject> = [
"titre": titre!,
"soustitre": soustitre!,
"text": text!,
"votes": votes
]
ref.childByAppendingPath(current).childByAppendingPath("Posts").childByAutoId().setValue(newPosts)
ref.childByAppendingPath(current).observeEventType(.ChildAdded, withBlock: { snapshot in
print(snapshot.value)
从这里我真的迷路了,我在教程中找到了这部分,但老实说我没有得到它。
var posts = [NSDictionary]()
for item in snapshot.children{
let child = item as! FDataSnapshot
let dict = child.value as! NSDictionary
posts.append(dict)
}
self.TextLabel.text = snapshot
})
}
任何线索都会非常有用!
感谢您的宝贵时间!
【问题讨论】:
标签: ios swift dictionary firebase