使用findObjectsInBackgroundWithTarget时,在调用中缺少参数#1的参数

时间:2015-04-26 08:01:00

标签: ios xcode swift xcode6.3

我正在尝试从Parse获取一系列PFObjects [PFObject]并查看下面的问题。我错过了什么?

错误是呼叫

中缺少参数#1的参数
func loadData() {
    rooms = [PFObject]()
    users = [PFUser] ()

    self.tableView.reloadData()

    let pred = NSPredicate(format: "user1 = %@ OR user2 = %@", PFUser.currentUser()!, PFUser.currentUser()!)

    let roomQuery = PFQuery(className: "Rooms", predicate: pred)

    //gives us all the information - includeKey all columns for the user class itself
    roomQuery.includeKey("user1")
    roomQuery.includeKey("user2")

    roomQuery.findObjectsInBackgroundWithTarget{ (results: [AnyObject]!, error: NSError!) -> Void in

        if error == nil {
            self.rooms = results as [PFObject]

            for room in self.rooms {
                let user1 = room.objectForKey("user1") as PFUser
                let user2 = room.objectForKey("user2") as PFUser

                if user1.objectId != PFUser.currentUser() {
                    self.users.append(user1)
                }

                if user2.objectId != PFUser.currentUser() {
                    self.users.append(user2)
                }
            }
         self.tableView.reloadData()

        }


    }

}

错误: enter image description here

1 个答案:

答案 0 :(得分:3)

您似乎想要使用块来处理响应,但您决定使用findObjectsInBackgroundWithTarget。你应该使用findObjectsInBackgroundWithBlock:。所以你应该有这样的东西:

roomQuery.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in