【发布时间】:2015-09-09 15:27:53
【问题描述】:
我只想打印孩子的数量并将其设置为标签。
这是我的 JSON 结构:
-
simplelogin2
- 姓名
- 年龄
- 发帖
- post1:“asdasd”
- post2:“sadasd”
- post3:“asdasd”
我想打印帖子中的儿童数量或将其设置为标签我该怎么做?
我试过这个:
ref.childByAppendingPath("users").childByAppendingPath(ref.authData.uid).childByAppendingPath("post").observeSingleEventOfType(.Value, withBlock: { snapshot in
self.postCount = snapshot.childrenCount.value
println(self.postCount)
})'
但它说 word 不能转换为 uint。
更新:
这就是我创建用户的方式:
var userId = authData.uid
let newUser = [
"Provider" : authData.provider,
"email" : authData.providerData["email"] as? NSString as? String,
"name" : self.Name.text,
"Image" : "",
"location" : "",
"about" : "",
"age" : "",
]
self.ref.childByAppendingPath("users").childByAppendingPath(authData.uid).setValue(newUser)
这就是我向每个用户添加子“帖子”的方式!
(在一个按钮内我做了这个编码)
ref.childByAppendingPath("users/\(ref.authData.uid)/post").childByAutoId().setValue(text.text)
【问题讨论】:
-
我这样做是因为我想打印已登录用户的帖子的孩子数!
-
问题不明确
-
发布更多代码或显示错误
-
我的问题是我如何获取用户的孩子的孩子数!
-
您需要显示更多代码。我们需要查看快照的定义以确定如何获取其子项的计数。