MakeSchool-Tutorials / Makestagram-Swift-V3

14 stars 7 forks source link

20. Setting-Followers - Solution code error? #25

Closed liang162 closed 7 years ago

liang162 commented 7 years ago

screen shot 2017-06-09 at 12 02 46

let ref = Database.database().reference().child(**"followers"**).child(currentUID) should be: let ref = Database.database().reference().child(**"following"**).child(currentUID) ref.queryEqual(toValue: nil, childKey: **currentUID**).observeSingleEvent(of: .value, with: { (snapshot) in should be: ref.queryEqual(toValue: nil, childKey: **user.uid**).observeSingleEvent(of: .value, with: { (snapshot) in

The suggested solution will not give me the correct information about if a user is following another user. If I switch to another tab, and go back, it will not show "following" any more, even though the database shows the correct information.

I am not sure if this is something with the structure of my database, but the above changes fixed the problem.

ocwang commented 7 years ago

Good catch! The code you've implemented will give the correct results as well, but querying from the current user's perspective instead of the user argument.

In the current tutorial, changing the code below should fix the bug:

Database.database().reference().child("followers").child(currentUID)

should be fixed to

Database.database().reference().child("followers").child(user.uid)