0

I want to run a query to determine the number of rows in a tableView in Swift. When I use the query results.count method I get the following error:

Int? is not convertible to 'Void'

Here is the function that is throwing the error:

 override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        if let user = self.user {

            var currentUserQuery = PFQuery(className: "Game")
            currentUserQuery.whereKey("user1", equalTo: PFUser.currentUser()!)
            currentUserQuery.whereKey("isActive", equalTo: true)

            var currentUserQuery2 = PFQuery(className: "Game")
            currentUserQuery2.whereKey("user2", equalTo: PFUser.currentUser()!)
            currentUserQuery2.whereKey("isActive", equalTo: true)

            var query = PFQuery.orQueryWithSubqueries([currentUserQuery, currentUserQuery2])
            query.findObjectsInBackgroundWithBlock{
                (results: [AnyObject]?, error: NSError?) -> Void in

                if error != nil {
                    println(error)
                }

                if error == nil{

                    //continue an active game that already exists with the user
                    if results != nil{

                        return results!.count as? Int

If I change (results: [AnyObject]?, error: NSError?) -> Void to (results: [AnyObject]?, error: NSError?) -> Int I get a different error:

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

What should I do?

Thanks!

winston
  • 3,000
  • 11
  • 44
  • 75

1 Answers1

0

You need to remove the ? from your return, it is up to the declaration of the function to decide if those values are optional or not.

(results: [AnyObject], error: NSError) -> Void in
Icaro
  • 14,585
  • 6
  • 60
  • 75
  • Thanks for the reply! When I do that I get `Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject], NSError) -> Void)'` – winston May 20 '15 at 02:01
  • It still seeing "'(([AnyObject]?, NSError?) -> Void)'" see they "?" in the type? It should not be there you need to delete it, they type must be "'(([AnyObject], NSError) -> Void)" – Icaro May 20 '15 at 02:03
  • Sorry, that was a bad copy/paste. It doesn't see the question mark. The error is `Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject], NSError) -> Void)'` – winston May 20 '15 at 02:06
  • Have a look in this page maybe help http://stackoverflow.com/questions/29842864/cannot-invoke-findobjectsinbackgroundwithblock-swift-error – Icaro May 20 '15 at 02:07