I just updated a working Swift 2 to Swift 3 program, and I am getting the error,
Cannot convert value of type '(Data?, NSError?) -> Void' to expected argument type 'GTMSessionFetcherCompletionHandler?'
Here are the relevant details (I hope):
let fetcher = GTMSessionFetcher(urlString:url)
fetcher.authorizer = parentController.service.authorizer
fetcher.beginFetch(completionHandler: handleDownload(studentNum))
^^^^ causing the error
The function for the completionHandler:
func handleDownload(_ studentNum:Int) -> (Data?, NSError?) -> Void {
return { (data: Data?, error: NSError?) -> Void in
// code for function
}
}
GTMSessionFetcherCompletionHandler
is defined in an Objective-C header, as follows:
#define GTM_NULLABLE_TYPE __nullable
typedef void (^GTMSessionFetcherCompletionHandler)(NSData * GTM_NULLABLE_TYPE data,
NSError * GTM_NULLABLE_TYPE error);
I have tried changing handleDownload() to the following:
func handleDownload(_ studentNum:Int) -> (GTMSessionFetcherCompletionHandler?) {
return { (data: Data?, error: NSError?) -> Void in
// code for function
}
}
but that moves the error down to this function: "Cannot convert return expression of type '(Data?, NSError?) -> Void' to return type 'GTMSessionFetcherCompletionHandler?'"
I can't figure out how to keep the curried (?) data and error variables, and have it compile.