swift - 如果你想在firebase数据库中获取条件的Childs数量,该怎么做?
问题描述
需要注意的是,他们应该从今天开始。由于时间戳根据定义是一个时间点,因此您还可以使用它们将计数限制为从今天开始的计数。
以下是我想出的,但仍然有错误var timestampDate
:(
使用未声明的类型“时间间隔”
概括:
- 时间戳Childs的计数是我们想要的。
- 但只有今天的时间戳。
代码:
let uid1 = Auth.auth().currentUser!.uid
var today: Date = Date.init()
let thisUserRef1 = Database.database().reference().child("people").child(uid1)
let myPeopleRef1 = thisUserRef1.child("peopleWhoLike2")
myPeopleRef1.observeSingleEvent(of:DataEventType.value, with: { snapshot in
print(snapshot)
var timestampDate: timeinterval = snapshot
var otherDate: Date = Date.init(timeIntervalSince1970: timestampDate)
let calendar: Calendar = Calendar.current
let result = calendar.dateComponents([.day], from: timestampDate, to: today)
print("result.day")
let thisUserRef = Database.database().reference().child("people").child(uid1)
let myPeopleRef = thisUserRef.child("peopleWhoLike2")
.queryOrderedByValue().queryEqual(toValue:result.day<1 )
myPeopleRef.observeSingleEvent(of:DataEventType.value, with: { snapshot in
print(snapshot.childrenCount, "ooooo")
})
})
解决方案
不
var timestampDate: timeinterval = snapshot
timeinterval需要是TimeInterval
IEvar timestampDate: TimeInterval = snapshot
TimeInterval 是一种类型,因此您需要使用正确的大写字母来拼写它。
推荐阅读
- firebase-realtime-database - Mat-table 按列过滤来自 Firebase 的数据
- c++ - 如何从 DirectX 11 中的着色器汇编代码编译?
- assembly - ARM 程序集错误 - 修复后常量无效
- python - 如何在 sklearn.model_selection 的 GridSearchCV 库中修复这个已经启动的运行时错误
- dart - 为什么这个 bloc getter 在 null 上调用?
- html - 我如何使用一个 CSS 样式表,该样式表从我试图访问它的文件中上升 2 个目录?
- css - How to highlight paragraphs on hover using pseudo element
- python - 用漂亮的汤从网站上刮掉一串文本
- ms-access - 就像 Nz 不处理空值
- ethereum - 调用其余 API ( /storeraw ) 时出现 Tessera 跨域问题