gpt4 book ai didi

swift - 解析和 Swift 问题查询

转载 作者:行者123 更新时间:2023-11-28 09:03:54 24 4
gpt4 key购买 nike

这是我的错误信息:

Cannot invoke 'getObjectInBackgroundWithId' with an argument list of type '(String, (PFObject!,NSError!) -> Void)'

我的代码是这样的:

    func CallData(){

var query : PFQuery = PFQuery(className: "QuestionsandAnswers")
query.getObjectInBackgroundWithId("iXCrgCLKk2"){
(Object : PFObject!, error : NSError!) -> Void in
if (error == nil){
self.Question = Object["Question"] as String!
self.Answers = Object["Answers"] as Array!
self.Answer = Object["Answer"] as String!

if (self.Answers.count > 0){
self.QuestionLabel.text = self.Question
}
} else {
NSLog("There is something wrong!")
}
}
}

我试过更改 PFObjectNSError 后面的感叹号/问号/什么都没有,但没有任何效果。但是,如果我在 PFObjectNSError 后面都加上问号,我会收到一条新的错误消息:

'AnyObject' is not convertible to 'String!';did you mean to use 'as!' to force downcast?

如果我将代码更改为 as!,则会出现此错误:

Cannot assign immutable value of type 'String!'

关于如何解决这个问题的任何想法?感谢您的帮助!

最佳答案

看看: http://blog.parse.com/announcements/building-apps-with-parse-and-swift/

我觉得这行得通

var query = PFQuery(className: "QuestionsandAnswers")
query.getObjectInBackgroundWithId("iXCrgCLKk2", block: { (object:PFObject?, error:NSError?) -> Void in
if let error = error {
//error
} else if let object = object{
//do something with your object as PFObject
// such as
var Question:String = object.objectForKey("Question") as! String

}
})

关于swift - 解析和 Swift 问题查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31331835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com