Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining typealias in Swift 3 for closures

Tags:

ios

swift

swift3

I'm trying to define a type alias for a closure in swift 3 like that:

 public typealias URLRequestClosure = (response: URLResponse?, data: Data?, error: Error?) -> Void

I get an error that I'm supposed to put underscore before the parameters' names. i.e: public typealias URLRequestClosure = (_ response: URLResponse?, _ data: Data?, _ error: Error?) -> Void can anyone explain me why? Is it something to do with Swift 3?

Thanks a lot

like image 548
Gal Marom Avatar asked Feb 05 '23 21:02

Gal Marom


1 Answers

You can't specify parameter names in closure typealias. So instead of:

public typealias URLRequestClosure = (response: URLResponse?, data: Data?, error: Error?) -> Void

You should use:

public typealias URLRequestClosure = (URLResponse?, Data?, Error?) -> Void
like image 198
Midhun MP Avatar answered Feb 19 '23 16:02

Midhun MP