Peter
Peter

Reputation: 45

How can I retrieve data from Parse, using getObjectInBackgroundWithId and saveInBackgroundWithBlock

I'm trying to retrieve data, by using Parse (V 1.7.5) for swift. I was successfully able to save data using saveInBackgroundWithBlock, but once I'm trying to retrieve data using the getObjectInBackgroundWithId I'm getting the following error msg:

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

    import UIKit
    import Parse

    class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()


    Parse.setApplicationId("j6jI1g1gz003zqUQTVWez7AwPUedTiPLIcJp9tGP",
        clientKey: "PEz03P1EUp6eK38wzlVCCvveOxXhzUGCbpGarFK1")

    var userId = "2Zn8ZfFKsA"
    var query = PFQuery(className: "score")


    query.getObjectInBackgroundWithId("2Zn8ZfFKsA") {


        (score: PFObject!, error: NSError?) -> Void in

        if error == nil {

            println(score)

        } else {

            println(error)

        }
    }
}

I also tried to do it on this way:

    [query whereKey:"objectId" equalTo: userId];

    [query findObjectsInBackgroundWithBlock: ^{ (score: PFObject!, error: NSError?) -> Void in

        if error == nil {

            println(score)

        } else {

            println(error)

        }
    }];

But I got more errors.. Please, hope to get an answer how to keep from here.

Upvotes: 0

Views: 485

Answers (1)

villy393
villy393

Reputation: 3073

This should work.

query.getObjectInBackgroundWithId("2Zn8ZfFKsA") {
    (score: PFObject?, error: NSError?) -> Void in
    if error == nil && score != nil {
        println(score)
    } else {
        println("error")
    }
}

Upvotes: 1

Related Questions