【问题标题】:Access all firebase user's information访问所有 firebase 用户的信息
【发布时间】:2017-03-13 14:27:57
【问题描述】:

我正在创建一个类似于 Instagram 的应用。我使用此代码创建了一个登录用户提要选项卡

FIRDatabase.database().reference().child("posts").child(self.loggedInUser!.uid).observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in

  let key = snapshot.key
    let snapshot = snapshot.value as? NSDictionary
    snapshot?.setValue(key, forKey: "uid")
    print(snapshot)
    if(key == self.loggedUser?.uid)
    {
        print("same as logged in user")
    }
    else
    {
    self.usersArray.append(snapshot)
         self.followUsersTableView.insertRows(at: [IndexPath(row:self.usersArray.count-1,section:0)], with: UITableViewRowAnimation.automatic)
    }



    }) { (error) in
        print(error.localizedDescription)

    }

但是,我想创建一个输出数据库帖子中所有用户的选项卡,但是当我使用此代码时

FIRDatabase.database().reference().child("posts").observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in

它不起作用。

我的 Firebase 数据库如下所示

有没有办法可以访问所有用户的标题节点,而不仅仅是登录用户。

【问题讨论】:

标签: ios swift firebase


【解决方案1】:

你可以这样做

FIRDatabase.database().reference().child("posts").observeSingleEvent(of: .value, with: { (snapshot) in
    for child in snapshot.children {

        if let item = child as? FIRDataSnapshot {

            // get values
            let foo = item["index"] as? String

        }

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-14
    • 2018-09-20
    • 1970-01-01
    • 2021-03-29
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    相关资源
    最近更新 更多