无法访问 Firebase Snap 数据

Cannot Access Firebase Snap Data

我有一个 firebase 结构设置如下:

每个键都包含我想用来填充 UICollectionView 的数据。但是,我无法访问 Firebase 数据。在Android中,我使用了类似

的方法
dataSnapshot.child("xxx").getValue()

但是,iOS 似乎不提供这种类型的辅助功能。以下是我正在尝试的方法:

     self.dataSource = self.collectionView?.bind(to: self.ref.child("Polls")) { collectionView, indexPath, snap in
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PollCell
        /* populate cell */
        cell.pollQuestion.text = snap.child("question").getvalue
          print(indexPath)

        return cell
    }

我收到一条错误消息,指出 "FIRDataSnapshot" 类型的值没有子成员

如果 Android 上有这条线:

dataSnapshot.child("xxx").getValue()

在 iOS 上将是:

snapshot.childSnapshot(forPath: "xxx").value

对于此类问题,我强烈建议使用 Firebase 参考文档:https://firebase.google.com/docs/reference/ios/firebasedatabase/api/reference/Classes/FIRDataSnapshot#-childsnapshotforpathFIRDataSnapshot中方法的数量并没有那么多,它会让你进步得更快。