1
votes

So I ran into this error when getting all the users from parse to my application:

Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject]!, NSError!) -> Void)'

trying to run this code:

    var userQuery = PFUser.query()
    userQuery.findObjectsInBackgroundWithBlock({(objects: [AnyObject]!, error: NSError!) -> Void in


        self.users.removeAll(keepCapacity: true)

        for object in objects {
            var user:PFUser = object as PFUser

            self.users.append(user.username)
        }

        self.tableView.reloadData()


    })

I am using xcode 6.3, is there any solutions? I've tried adding "?" instead of "!" after [AnyObject] but nothing seems to help.

2
self.users.removeAll(keepCapacity: false). If you don't maintain capacity then what happens?. Try this also self.users = query.findObjects() - Ajay Gabani
The code you write is correct.. - Ajay Gabani
None of that seems to work.. The code should be correct, don't know why it's throwing this error at me.. - MrFoffoloff
Just tested below code works fine. If this not works then start with initials: Check you applicationID and ClientID and important part is User table must contains records :P - Ajay Gabani

2 Answers

1
votes

I actually got it working with doing the coding like this

var data: Void? = query?.findObjectsInBackgroundWithBlock({(objects:[AnyObject]?, error:NSError?) -> Void in
        self.users.removeAll(keepCapacity: true)

            for object: AnyObject in objects! {
            var user:PFUser = object as! PFUser
            self.users.append(user.username!)
        }
        self.tableView.reloadData()
    })
0
votes

These lines of code works fine:

 var losingUserQuery = PFUser.query()
    losingUserQuery.findObjectsInBackgroundWithBlock {
        (results: [AnyObject]!, error: NSError!) -> Void in
        if error == nil && results != nil {

                            self.arrayMyPostsFromParse.removeAll(keepCapacity: false)

                            for usr in results{
                                var user:PFUser = usr as PFUser

                                 self.arrayMyPostsFromParse.append(user.username! as NSString
                            }

                            self.tblUsers.reloadData()

                        } else {
                            println(error)
                        }
    }