Defining types in Swift 3 to close

I am trying to define the type alias to close in swift 3 as follows:

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

I get an error that I have to put an underscore in front of the parameter names. that is:   public typealias URLRequestClosure = (_ response: URLResponse?, _ data: Data?, _ error: Error?) -> Void can someone explain to me why? Is it related to Swift 3?

Thank you so much

+4
source share
2 answers

You cannot specify parameter names in closure types. Therefore, instead of:

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

You should use:

public typealias URLRequestClosure = (URLResponse?, Data?, Error?) -> Void
+7
source

The general signature of the swift method is similar to the name func (Param1 param1: param1Type, Param2 param2: param2Type) -> returnType

- , , .

typeAliasing , (Param1, Param2) underScore

underScore .

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

Source: https://habr.com/ru/post/1658490/


All Articles