1

So I am trying to get a String that is saved within an object from Parse.com. Here is the code that I am using to do so:

var query: PFQuery = PFQuery(className: "Replys")
    query.getObjectInBackgroundWithId("ipmdKB0N1N") {
        (object: PFObject?, error: NSError?) -> Void in
        if error == nil && object != nil {
            println(object)
            self.replyField.text = object["Replys"]
        } else {
            println(error)
        }
    }

I want to make this string the text of the label called "replyField" but when I try to do that, Xcode gives an error like "Cannot assign value "AnyObject?" to type "String?"" Even when I add as! String, it still gives a similar (though not exactly the same) error. Any ideas why?

2 Answers 2

1

You should unwrap optional of object. Such as object!["Replys"] or object?["Replys"]

Like below:

self.replyField.text = object!["Replys"] as! String

or

self.replyField.text = object?["Replys"] as! String 
Sign up to request clarification or add additional context in comments.

Comments

1
let replysString = object["Replys"] as! NSString
self.replyField.text = replysString as String

3 Comments

I have tried that, but it says that the type is not convertible to string
Is it stored as a string in the database?
Yes, the entire column is designated as a String type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.