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!