我想运行一个查询来确定Swift中tableView中的行数。当我使用查询results.count方法时,我收到以下错误:
Int? is not convertible to 'Void'
这是抛出错误的函数:
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
如果我将(results: [AnyObject]?, error: NSError?) -> Void
更改为(results: [AnyObject]?, error: NSError?) -> Int
,我会收到其他错误:
Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject]?, NSError?) -> Int)'
我该怎么办?
谢谢!
答案 0 :(得分:0)
你需要删除?从你的回归中,由函数声明决定这些值是否是可选的。
(results: [AnyObject], error: NSError) -> Void in