问题
I get a weird error in my iOS swift app. The compiler complains at the first row of:
let task = session.dataTaskWithRequest(request) { data, response, error in
self.oauthManager.customOAuth2Manager.parseData(data, response: response, error: error, body:request, callback: { (jsonArray, error) -> Void in
})
}
The compiler error is:
Cannot invoke 'dataTaskWithRequest' with an argument list of type '(NSURLRequest, (_, _, _) -> _)'
However, it's not on that row the error seems to be located. If I remove the inner call to parseData the error does not appear.
The declaration to parseData is:
func parseData(data: NSData, response:NSURLResponse, error:NSError?, body:String?, callback:JsonRequestCallback)
where JsonRequestCallback is:
public typealias JsonRequestCallback = (jsonArray: NSArray?, error: NSError?) -> Void
Also:
let request = oauthManager.newLoginRequest(emailOrCompanyCode: emailOrCompanyCode, password: password) as NSURLRequest
let session = NSURLSession.sharedSession()
and
func newLoginRequest(var #emailOrCompanyCode: String, var password:String?) -> NSMutableURLRequest
Any ideas?
回答1:
To answer my own question, Satachito was correct. Just an invalid parameter. Unfortunately the Swift compiler does not specify the exact error, not the correct line for this.
So for others having similar issues, look for misstakes in all code in any passed closures
来源:https://stackoverflow.com/questions/30103902/cannot-invoke-datataskwithrequest-with-an-argument-list-of-type