func retrieveMessages() {
var query:PFQuery = PFQuery(className: "Message")
//Call findobjectsinbackground
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
self.messagesArray = [String]()
for messageObject in objects { <<<<<<<<<<<<<<<<< error
let messageText:String? = (messageObject as PFObject)["Text"] as? String
if messageText != nil {
self.messagesArray.append(messageText!)
}
}
self.messageTableView.reloadData()
}
}
From this code an error occurs saying: [AnyObject]? does not have a member named 'Generator'
. Is there a way how to correct this?
Your objects
array is declared as an Optional : objects:[AnyObject]?
So you need to unwrap it before looping over it:
for messageObject in objects! {
// do stuff
}
And since objects
can be nil, better do this:
if let myObjects = objects {
for messageObject in myObjects {
// do stuff
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With