Reputation: 5924
I have a tableview that populates with all of the Parse users in my database. I am trying to display all of the users except for the currently logged in user. My current solution is to only add objects to my array if they satisfy this condition
if user.username != PFUser.currentUser().username
Unfortunately, this creates an issue as nothing is populated in my table.
Here is my full function:
var userArray : NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
var user = PFUser.currentUser()
loadParseData()
}
func loadParseData() {
var user = PFUser.currentUser()
var query : PFQuery = PFUser.query()
query.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]!, error:NSError!) -> Void in
if error == nil {
if let objects = objects {
println("\(objects.count) users are listed")
for object in objects {
if user.username != PFUser.currentUser().username {
self.userArray.addObject(object)
}
}
self.tableView.reloadData()
}
} else {
println("There is an error")
}
}
}
Upvotes: 0
Views: 829
Reputation: 909
You may want to take a look into the subclass PFQueryTableViewController -> https://parse.com/docs.
There is an example in there of how to use this subclass, inside is a method for returning a query to the tableviewcontroller.
You will then find it easier performing this task using a queries again in the docs but it would look something like this.
var query = PFUser.query
query.wherekey(username, notEqualTo: PFUser.currentUser.username)
return query
Upvotes: 2