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---
self.timelineData.addObject(object)
}
}
}
Any suggestions?
Thanks!
You can help the compiler know what objects
is like this:
for object in objects as! [PFObject] {
self.timelineData.addObject(object)
}
if let pfObjects = objects as? [PFObject]
{
for pfObject in pfObjects
{
self.timelineData.addObject(pfObject)
}
}
...exclamation points in Swift code give me the heeby jeebies.
If you are writing some code likes:
for (i, view) in views {
}
You need to add enumerated
:
for (i, view) in views.enumerated() {
}
And now it should work.
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