1

I'm trying to put into a variable my PFObject (I'm using Parse):

func retrieveScore() {


    var query:PFQuery = PFQuery(className: "Score")


    query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in


        for varScore in objects! {
            let scoreExtract:Int? = (varScore as? [PFObject]) as? Int
        }
    }
}

But it gives to me this error: "Cast from '[PFObject]' to unrelated type 'int' always fails.

How can I extract the object into a variable? I need an array?

thank you.

Luca Alberto
  • 1,195
  • 3
  • 11
  • 30

1 Answers1

0

What you are doing is first converting varScore to an Array of PFObject and then converting that Array to an Int. How can you convert an Array to Int?

If objects contains Array of PFObject then,

func retrieveScore() {
   var query:PFQuery = PFQuery(className: "Score")
   query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in

      for varScore in objects! {
          let score = varScore as? PFObject
          let youeIntPropertyValue = score.someIntProperty// a property in Score class/struct.
      }
   }
}
Amit89
  • 3,000
  • 1
  • 19
  • 27