I am new to ios development and I recently found a tutorial to build a tweeter like ios app using a parse backend. My current set up is Xcode 7.1 with swift 2.0, the tutorial was done on an older version of swift so I had to adjust some of the swift syntax in order to make it work. I was doing fine until I hit the following error,
func loadData(){
timelineData.removeAllObjects()
var findTimelineData:PFQuery = PFQuery(className: "Tweet")
findTimelineData.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]?, error:NSError?) -> Void in
if (error == nil && objects != nil){
for object:PFObject! in objects!{
self.timelineData.addObject(object)
}
let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
self.timelineData = array as! NSMutableArray
self.tableView.reloadData()
}
}
Here I am trying to access/store all the data in a parse table/class into an array. And the editor is complaining about the closure argument (objects:[AnyObject]?, error:NSError?) -> Void in. After a couple of tries,
All the options I tried gave me the same error: '([AnyObject]!, NSError!) -> Void' is not convertible to 'PFQueryArrayResultBlock?'
In fact for (objects:[AnyObject]?, error:NSError?) -> Void in (which I thought makes the most sense), the editor would crash and if I ran the code I would get a seg fault.
Has anyone run into similar issue? or know of a fix?
Thank you for your help in advance.
Try changing [AnyObject]? to [PFObject]?. This seems to be required by Swift 2.0.
So instead of:
findTimelineData.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]?, error:NSError?) -> Void in
Use:
findTimelineData.findObjectsInBackgroundWithBlock {
(objects:[PFObject]?, error:NSError?) -> Void in
You'll also need to change your iteration over the array objects, since they will now already be PFObject.
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