Kody R. Kody R. - 1 year ago 78
Swift Question

Error: 'Type of expression is ambiguous without more context'

I'm pretty new to coding Swift, so please excuse me if this error is a simple answer!

I keep getting an error message that says "Type of expression is ambiguous without more context."

var findTimelineData: PFQuery = PFQuery(className: "Sweets")
findTimelineData.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]?, error:NSError?) -> Void in

if error == nil {
for object:PFObject in objects! { // ----This is the error line---

I understand what the problem is, I'm just not certain how to go about fixing it. I've seen other questions about this answered, but none about iterating through an array of AnyObject.


Answer Source

You can help the compiler know what objects is like this:

for object in objects as! [PFObject] {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download