1

I am trying to receive a string from Parse in swift but I get an error saying: AnyObject is not convertible to String Here is my code:

var query = PFQuery(className:"NewsClass")
query.getObjectInBackgroundWithId("5tZMCa5XyX") {
    (news3: PFObject?, error: NSError?) -> Void in
    if error == nil && news3 != nil {
        println(news3)
        let description3 = news3["Description"] as! String


    } else {
        println(error)
    }
}
jacob
  • 129
  • 2
  • 17
  • In swift, strings and int are objects, you need to cast it to object using NSString and NSInteger. Pl. refer to the below stack over flow discussion http://stackoverflow.com/questions/25449080/swift-anyobject-is-not-convertible-to-string-int – shri Sep 15 '15 at 05:51
  • @shri I get the same error when casting it as a NSString – jacob Sep 15 '15 at 05:58
  • Try it as a conditional cast: `if let description = news3["Description"] as? String { ...` – Dan Nichols Sep 15 '15 at 06:11
  • @DanNichols When I try that I get an error saying `String? is not convertable to StringLiteralConvertable` – jacob Sep 15 '15 at 14:35
  • 1
    it should be if let description = news3!["Description"] as? String { – OverD Jan 08 '16 at 19:44

0 Answers0