Price Garrett
Price Garrett

Reputation: 35

Parse and Swift Xcode 6.3 issue

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

Upvotes: 0

Views: 309

Answers (2)

Automate This
Automate This

Reputation: 31394

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

Upvotes: 1

Aaron Brager
Aaron Brager

Reputation: 66302

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.

Upvotes: 0

Related Questions