我真的有一个来自firebase 3的获取用户的代码。但是需要获取除当前用户之外的所有用户。在我的新消息控制器中,我想要获取用户。
Name count
a 2
b 1
答案 0 :(得分:0)
试试这个,
func fetchUserExceptCurrent() {
Database.database().reference().child("users").observe(.childAdded, with: { (snapshot) in
print(snapshot)
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
user.id = snapshot.key
user.name = dictionary["name"] as? String
user.email = dictionary["email"] as? String
user.profileImageUrl = dictionary["profileImageUrl"] as? String
let currentUser = Auth.auth().currentUser?.uid
let currentUserID : String = (FIRAuth.auth()?.currentUser?.uid)! //get current user id
//Filter current user
if user.id != currentUserID {
self.users.append(user)
} else {
debugPrint("Current user filtered")
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}, withCancel: nil)
}