1
votes

This is my error message:

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

This is what my code looks like:

    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!")
        }
    }
}

I have tried changing around the exclamation point/question mark/nothing behind PFObject and NSError but nothing works. However, if I make it a question mark behind both PFObject and NSError I get a new error message that says:

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

If I change the code to as! then I get this error:

Cannot assign immutable value of type 'String!'

Any ideas on how to fix this? Any help is appreciated!

1

1 Answers

0
votes

have a look to : http://blog.parse.com/announcements/building-apps-with-parse-and-swift/

i think this will work

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

        }
    })