我是 iOS 和 Swift 的初学者,似乎无法截断数据库评论列表以仅显示当前活跃的评论。
评论有一个结束时间戳字段,它是一个整数,例如:1507522353
这是获取 10 条以上评论的代码区域:
commentsRef.observe(.childAdded, with: { (snapshot) -> Void in
self.comments.append(snapshot)
self.tableView.insertRows(at: [IndexPath(row: self.comments.count-1, section: self.kSectionComments)], with: UITableViewRowAnimation.automatic)
})
我只想附加(和显示)结束时间戳<当前时间戳的注释
谢谢
最佳答案
您可以使用 queryEnding(atValue:)
实现此目的,其中值是当前时间戳(以毫秒为单位)减一。查询按 endtimestamp
排序,以便指定结束于值查询的子键。
let now = Date().timeIntervalSince1970 * 1000.0
let query = commentsRef
.queryOrdered(byChild: "endtimestamp")
.queryEnding(atValue: now - 1)
query.observe(.childAdded, ...
关于ios - 按特定字段截断 firebase 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46630271/