this is not a nested function but a chain of functions.
class Alamofire {
static func request(_ url: String)->Request {
//... code ...
return aRequest
}
}
class Request {
func responseJson(completion: (response: Response)->()) {
//code
}
}
So this is what is happening.
The request function of Alamofire is returning a Request object which has the responseJson function that accepts a closure as parameter.
In swift if the closure parameter is the last one, the function call can be synthesized by removing the parameter name and define the closure as a function so to do
Alamofire.request("whatever").responseJson(completion: { (response) in
//whatever
})
is exactly the same as doing
Alamofire.request("whatever").responseJson(){ (response) in
//whatever
}
This is a trailing closure. You can find more info about it here in the "Trailing Closure" paragraph.
Hope it helps