Reputation: 1305
I want to get a record from my parse.com class called "Tags" by ID. I want to retrieve data from the object "username" and "tagtext". Afterwords I want to save "username" to the String "username" and "tagtext" to the String "tagtext". My code looks like this, but I'm getting an error called 'AnyObject?' is not convertible to 'String'
in the commented section:
var query = PFQuery(className:"Tags")
query.getObjectInBackgroundWithId("IsRTwW1dHY") {
(gameScore: PFObject?, error: NSError?) -> Void in
if error == nil && gameScore != nil {
let username = gameScore["username"] as! String // Error here
let tagtext = gameScore["tagtext"] as! String // Error here
} else {
println(error)
}
}
Upvotes: 0
Views: 39
Reputation: 5845
In Swift String is not an object. You need to cast NSString instead of String. Once you do you can then assign your NSString to a variable of type String.
edit following comment
You can do something like this:
if let username = gameScore["username"] as? NSString {
// If we get here, we know "username" exists, and we know that we
// got the type right.
self.username = username
}
Upvotes: 2