斯威夫特/解析 - 无法调用“getObjectInBackgroundWithId”类型的参数列表“(?PFUser?(PFObject?NSError) - >无效)”

问题描述 投票:1回答:3

试图寻找对象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()
            }
        }
ios swift parse-platform
3个回答
2
投票

您使用了错误的参数类型传递给PFQuerygetObjectInBackground(_:block:)方法块。根据the docs,所述block参数采用一个NSArray(这可桥接至AnyObject的夫特阵列),以及一个错误:

query.getObjectInBackgroundWithId(user?.objectId) { (object: [AnyObject]?, error: NSError?) -> Void in
    // ...
}

此外,objectId参数应该是一个字符串,但你似乎是在传递一个PFUser实例。


1
投票

我不是专家,但是在看文档,我看到它接受String作为参数,而不是目的。

尝试使用:

query.getObjectInBackgroundWithId(user?.objectId)


1
投票

使用getObjectInBackgroundWithId是这样的:

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

        //your code

    })

正如你所看到的语法getObjectInBackgroundWithId是:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.