我在我的iOS Swift应用程序中有一个奇怪的错误。编译器在第一行提交:
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 }) }编译器错误是:
Cannot invoke 'dataTaskWithRequest' with an argument list of type '(NSURLRequest, (_, _, _) -> _)'但是,它不在该行似乎错误的位置。如果我删除对 parseData 的内部调用,则不会出现错误。
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.
声明为 parseData is:
func parseData(data: NSData, response:NSURLResponse, error:NSError?, body:String?, callback:JsonRequestCallback)其中 JsonRequestCallback 是:
public typealias JsonRequestCallback = (jsonArray: NSArray?, error: NSError?) -> Void另外:
let request = oauthManager.newLoginRequest(emailOrCompanyCode: emailOrCompanyCode, password: password) as NSURLRequest let session = NSURLSession.sharedSession()和
func newLoginRequest(var #emailOrCompanyCode: String, var password:String?) -> NSMutableURLRequest任何想法?
推荐答案为了回答我自己的问题,Satachito是正确的。只是一个无效的参数。不幸的是Swift编译器没有指定确切的错误,而不是正确的行。
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
更多推荐
无法使用类型的参数列表调用dataTaskWithRequest
发布评论