I'm having some struggles with the code when trying to retrieve an PFObject from Parse.
This is my code:
var query = PFQuery(className: "message")
query.whereKey("recipientUsername", equalTo: PFUser.currentUser())
var messages = query.findObjects()
var done = false
for message in messages {
if done == false {
var messageObject:PFObject =
done == true
The problem is in the "var messageObject:PFObject = ". I do not know what to write to complete this statement.
Any ideas on how to proceed would be appreciated.
Whatever you have to do with the
messageObjectvariable, you don't need it. ThefindObjectsmethod returns an array ofPFObjects. Since I presume that under the hood it returnsNSArray, which is translated to[AnyObject]in swift, you just have to downcast to an array ofPFObject:then in your loop the
messagevariable is automatically inferred thePFObjecttype, hence you don't need to create anothermessageObjectvariable:Update Sep 14, 2015: as of Swift 1.2, the new
as!forced conversion operator must be used:Thanks to
@Kiran Ruth Rfor pointing that out.