3 ms·
The trailing closure syntax [1] seems to be a point of pride with Swift. However, I feel that it’s grown to be a painful aspect of the language. Another example
by SebastianFrelle 8y ago
The trailing closure syntax [1] seems to be a point of pride with Swift. However, I feel that it’s grown to be a painful aspect of the language. Another example is when a function takes two closure arguments, e.g.:
func animate(withDuration duration: TimeInterval, animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil)
It is perfectly valid to call this function using a trailing closure for the latter argument, i.e.
animate(withDuration: 0.5, animations: { ... }) {
// handle completion here
}
rendering the `completion` parameter label obsolete and giving no clear visual indication that the trailing closure is a completion handler.
Again, I strongly dislike the visual similarity to control flow statements.
[1]: https://www.natashatherobot.com/swift-trailing-closure-syntax/ https://www.natashatherobot.com/swift-trailing-closure-synta...