Swift / Parse - 无法使用类型'的参数列表调用'getObjectInBackgroundWithId'(PFUser?,(PFObject?,NSError?) - > Void)'

时间:2015-08-10 10:42:59

标签: ios swift parse-platform

尝试搜索对象UserDetail时收到此错误消息。

错误消息

/Users/MNurdin/Documents/iOS/xxxxx/ViewController.swift:125:15: Cannot invoke 'getObjectInBackgroundWithId' with an argument list of type '(PFUser?, (PFObject?, NSError?) -> Void)'

我的代码

var user = PFUser.currentUser()

        var query = PFQuery(className:"UserDetail")
        query.getObjectInBackgroundWithId(user) { //error message here
            (gameScore: PFObject?, error: NSError?) -> Void in
            if error != nil {
                println(error)
            } else if let gameScore = gameScore {
                gameScore["cheatMode"] = true
                gameScore["score"] = 1338
                gameScore.saveInBackground()
            }
        }

3 个答案:

答案 0 :(得分:2)

您在传递给PFQuery的{​​{1}}方法的块中使用了错误的参数类型。根据{{​​3}},getObjectInBackground(_:block:)参数采用block(这可以桥接到NSArray的Swift数组),并出现错误:

AnyObject

此外,query.getObjectInBackgroundWithId(user?.objectId) { (object: [AnyObject]?, error: NSError?) -> Void in // ... } 参数应该是一个字符串,但您似乎是在objectId实例中传递。

答案 1 :(得分:1)

我不是专家,但看文档我发现它接受String作为参数而不是对象。

尝试使用:

query.getObjectInBackgroundWithId(user?.objectId)

答案 2 :(得分:1)

以这种方式使用getObjectInBackgroundWithId

query.getObjectInBackgroundWithId("yourUser", block: {
        (gameScore: PFObject?, error: NSError?) -> Void in

        //your code

    })

正如您所见,getObjectInBackgroundWithId的语法是:

enter image description here