Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error "Can't invoke 'findObjectInBackgroundWithBlock' with an argument list of type ((AnyObject!, NSError!) -> Void)

For below code, getting Can't invoke 'findObjectInBackgroundWithBlock' with an argument list of type ((AnyObject!, NSError!) -> Void) error and not able to run the parse query in background. Any thoughts?

var data = Query.findObjectsInBackgroundWithBlock(
        {(object:AnyObject!, error:NSError!) -> Void in

})
like image 228
Pandurang Yachwad Avatar asked Mar 17 '23 09:03

Pandurang Yachwad


2 Answers

If you are using swift 1.2 (Xcode 6.3) you need to call the function by:

var data = Query.findObjectsInBackgroundWithBlock({(objects:[AnyObject]?, error:NSError?) -> Void in

})

And if you are using swift 1.1 (Xcode 6.1, 6.2) you need to call the function by:

var data = Query.findObjectsInBackgroundWithBlock({(objects:[AnyObject]?, error:NSError!) -> Void in

})

This is different because of the swift update 1.2 which has changes with using optionals.

like image 73
siegy22 Avatar answered Apr 30 '23 03:04

siegy22


You should change object parameters type to array of AnyObject, and both parameters types to optional. So parameters should be (object: [AnyObject]?, error: NSError?).

Like below:

var data = Query.findObjectsInBackgroundWithBlock({(object: [AnyObject]?, error: NSError?) -> Void in

})
like image 44
kishikawa katsumi Avatar answered Apr 30 '23 05:04

kishikawa katsumi