PFObject can't be converted

37 views Asked by At

Then i try to convert a key from PFObject to a String it gives me a error. I can't find anything on Parses website. Please help

var findProgram = PFQuery(className: "Programs")

findProgram.getObjectInBackgroundWithId(data["program"] as! String!, block: { (object: PFObject?, error) -> Void in
      if error == nil {

          var objects = object["name"] as! String

          print(objects)

          self.programUpdated.append(object?.createdAt as NSDate!)

          }

})
2

There are 2 answers

3
Justin Rose On BEST ANSWER

I think this is what you're going to have to do, try this:

//explicitly giving the objects var a type of String
var objects:String = object["name"] as! String

You shouldn't get an error after that.

Good luck!

0
Dharmesh Kheni On

I think this will be the batter way to do that:

if let objects = object?.objectForKey("name") as? String{

    print(objects)
    self.programUpdated.append(objects?.createdAt as NSDate!)
}