首页 > 解决方案 > 如果你想在firebase数据库中获取条件的Childs数量,该怎么做?

问题描述

需要注意的是,他们应该从今天开始。由于时间戳根据定义是一个时间点,因此您还可以使用它们将计数限制为从今天开始的计数。

以下是我想出的,但仍然有错误var timestampDate:(

使用未声明的类型“时间间隔”

概括:

  1. 时间戳Childs的计数是我们想要的。
  2. 但只有今天的时间戳。

代码:

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")
                 })

           })

标签: swiftdatabasefirebasefirebase-realtime-database

解决方案


var timestampDate: timeinterval = snapshot

timeinterval需要是TimeInterval

IEvar timestampDate: TimeInterval = snapshot

TimeInterval 是一种类型,因此您需要使用正确的大写字母来拼写它。


推荐阅读