什么第一次不起作用?:
我获取的数据库条目的显示顺序
我正在运行这个
1st part In ViewDiDLoad
let thisUserRef = Database.database().reference().child("users").child(uid)
let myPeopleRef = thisUserRef.child("likers")
myPeopleRef.queryLimited(toLast: 30).observeSingleEvent(of: .value, with: { snapshot in
let userArray = snapshot.children.allObjects as! [DataSnapshot]
for person in userArray.reversed() where uid == Auth.auth().currentUser?.uid {
let personUid = person.value as! String
self.printPersonInfo(uid: personUid) //// this calls a DispatchQueue.main.async that appends the data in the array and reloads
}
})
func printPersonInfo(uid: String) {
print(uid)
let usersRef = Database.database().reference().child("users")
let thisUser = usersRef.child(uid)
thisUser.observeSingleEvent(of: .value, with: { snapshot in
let xx = snapshot.childSnapshot(forPath: "xx").value as? String ?? "No Entry"
let yy = snapshot.childSnapshot(forPath: "yy").value as? String ?? "No Entry"
let rr = snapshot.childSnapshot(forPath: "rr").value as? String ?? "No Entry"
let zz = snapshot.childSnapshot(forPath: "zz").value as? String ?? "No Entry"
let ll = snapshot.childSnapshot(forPath: "ll").value as? String ?? "No Entry"
let p = Usery(xx: xx, yy: yy, rr: rr, zz: zz, ll: ll)
self.person.append(p)
print(self.person, "person")
self.table.reloadData()
})
}
//////this gets the various data elements of the users that get displayed.
///////So to summarize, the query determines which users get displayed. This func determined which data of those users gets displayed.
过去 30 年的数据库整体示例
user K
user B
user F
user G
user K
user B
user K
.....
唯一不起作用的情况是您第一次安装干净的应用程序。那么它显示的顺序是
user K
user K
user B
user B
user F
user G
JSON
users
uid
likers
chailbyAutoID: uid1
chailbyAutoID: uid2