MrFoffoloff
MrFoffoloff

Reputation: 23

Cannot invoke findObjectsInBackgroundWithBlock swift error

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.

Upvotes: 1

Views: 1622

Answers (2)

MrFoffoloff
MrFoffoloff

Reputation: 23

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()
    })

Upvotes: 1

Ajay Gabani
Ajay Gabani

Reputation: 1178

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)
                        }
    }

Upvotes: 0

Related Questions