I currently have a query that returns a table of all the users that I have on my server along with a checkmark next to their name if I follow them. Here's the code:
//REFRESHER
func refresh() {
self.usernames.removeAll()
self.userIDs.removeAll()
self.isFollowing.removeAll()
let query = PFUser.query()
query?.findObjectsInBackground(block: { (objects, error) in
if error != nil {
print(error)
} else if let users = objects {
//self.usernames.removeAll()
//self.userIDs.removeAll()
//self.isFollowing.removeAll()
for object in users {
if let user = object as? PFUser {
if user.objectId != PFUser.current()?.objectId {
self.usernames.append(user.username!)
self.userIDs.append(user.objectId!)
let query = PFQuery(className: "Followers")
query.whereKey("follower", equalTo: PFUser.current()?.objectId)
query.whereKey("following", equalTo: user.objectId)
query.findObjectsInBackground(block: { (objects, error) in
if let objects = objects {
if objects.count > 0 {
self.isFollowing[user.objectId!] = true
} else {
self.isFollowing[user.objectId!] = false
}
if self.isFollowing.count == self.usernames.count {
self.tableview.reloadData()
self.refresher.endRefreshing()
}
}
})
}
}
}
//self.refresher.endRefreshing()
}
})
}
I'm trying to return a table with only users that I follow, however I can't seem to get it to work as my Followers class is outside of the PFUser class and thus it's difficult to append the usernames and userID's of users in the Follower's class.
My Followers class has four columns, follower and following which are the respective user ID's of each user, and then followerUsername and followingUsername which are the usernames of the respective users. Any help on this would be much appreciated. Thank you!
UPDATE: I'm now using pointers to reference follower and following in Parse and here's how I'm trying to query the users that I'm following. This implementation isn't working so if anyone could point me in the right direction I'd very much appreciate it!
func refresh() {
self.usernames.removeAll()
self.userIDs.removeAll()
self.isFollowing.removeAll()
let query = PFQuery(className: "Followers")
query.includeKey("following")
query.whereKey("follower", equalTo: PFUser.current()?.objectId)
query.findObjectsInBackground(block: { (objects, error) in
if error != nil {
print(error)
} else if let following = objects {
for object in following {
if let usersFollowing = object as? PFObject {
self.usernames.append(usersFollowing["followingUsername"] as! String)
self.userIDs.append(usersFollowing["following"] as! String)
if let objects = objects {
if objects.count > 0 {
self.isFollowing[usersFollowing["following"] as! String] = true
} else {
self.isFollowing[usersFollowing["following"] as! String] = false
}
if self.isFollowing.count == self.usernames.count {
self.tableview.reloadData()
self.refresher.endRefreshing()
}
}
}
}
}
})
}
HERE ARE MY 2 TABLES