0
votes

EDIT: I'm thinking this error might be due to the fact that Xcode 6.3 may have changed some features around and the query.getObjectInBackgroundWithId was one of them....

I am trying to run a query but when I run the method "query.getObjectInBackgroundWithId" , I am getting the error message:

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

override func viewDidLoad() {
    super.viewDidLoad()

    let score = PFObject(className: "gameScore")




    var query = PFQuery(className: "gameScore")
    query.getObjectInBackgroundWithId("HK0UbuTIQL", block: {
        (score: PFObject!, error: NSError?) -> Void in

        if error == nil  {

            println("pussiesPoundedCreated")

        } else {

            println(error)
        }
    })
}
2

2 Answers

1
votes

You can remove the block statement and unwrap the variables like this:

var query = PFQuery(className: "gameScore")
query.getObjectInBackgroundWithId("HK0UbuTIQL") {
  (gameScore: PFObject!, error: NSError?) -> Void in
  if error == nil && gameScore != nil {
    println(gameScore)
  } else {
    println(error)
  }
}

Parse.com documentation is pretty good and has Swift available for most all code examples. Here is a link to this topic

0
votes

This method takes a block with the argument signature (PFObject!, NSError!), but the block you wrote has an argument signature of (PFObject!, NSError?). Change NSError? to NSError!.

You should also use the trailing closure syntax in Portland Runner's answer because it's more readable.