Ios uint不能转换为int
我只想打印儿童计数并将其设置为标签 这是我的JSON结构:Ios uint不能转换为int,ios,swift,firebase,Ios,Swift,Firebase,我只想打印儿童计数并将其设置为标签 这是我的JSON结构: 单纯形2 名字 年龄 职位 post1:“asdasd” 帖子2:“萨达斯” post3:“asdasd” 我想打印post中的儿童计数或将其设置为标签,我该怎么做 我试过这个: ref.childByAppendingPath("users").childByAppendingPath(ref.authData.uid).childByAppendingPath("post").observeSingleEventOfTy
- 单纯形2
- 名字
- 年龄
- 职位
- post1:“asdasd”
- 帖子2:“萨达斯”
- post3:“asdasd”
ref.childByAppendingPath("users").childByAppendingPath(ref.authData.uid).childByAppendingPath("post").observeSingleEventOfType(.Value, withBlock: { snapshot in
self.postCount = snapshot.childrenCount.value
println(self.postCount)
})'
但它说这个词不能转换成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)
这就是我如何向每个用户添加子“post”的方法
(在一个按钮内,我进行了编码)
根据Firebase文档,childrenCount是一个整数
@property (readonly, nonatomic) NSUInteger childrenCount
我会放弃.value调用,因为它不需要。还可以使用字符串插值将值转换为字符串
ref.childByAppendingPath("users").childByAppendingPath(ref.authData.uid).childByAppendingPath("post").observeSingleEventOfType(.Value, withBlock: { snapshot in
self.postCount = snapshot.childrenCount
println("\(self.postCount)")
})
如果您在某个地方有一个UILabel,希望将后计数设置为文本,请执行以下操作。注意,例如,我的UILabel称为just label
label?.text = "\(self.postCount)"
注意标签上的问号。因为文本是可选属性,所以我们使用可选链接来设置值 我是这样做的,因为我想打印登录用户的儿童帖子数!问题是含糊不清Post more code或show the Error我的问题是如何获得用户的子级的子级计数!您需要显示更多的代码。我们需要查看快照的定义,以确定如何获得其子项的计数。感谢您的回复,但使用您的代码,它在标签上显示为nil,还有一件事,当我键入println(“(self.postcount)”)时在singleevent方法之外,但在视图内部确实加载了它,它给了我零,如果我在singleevent方法中键入它,它将正确打印计数。。现在我该怎么办@比尔兹利先生谢谢你,先生!它起作用了:)我在SingleEventMethod中将标签设置为postCount。。。再次感谢:)太好了!很高兴听到它起作用了。很抱歉耽误了你的答复。
label?.text = "\(self.postCount)"