I do not really have a problem with it, but am wondering just theoretically...
PHPhotoLibrary's performChanges(_:completionHandler:) exists. How come completionHandler closure is not declared as escaping, when changeBlock is declared as escaping?
Or more general question:
If I define a function with two closure parameters where the second closure is called after the first one is finished, and the first closure is escaping, does the second closure have to be escaping as well?
PHPhotoLibrary's performChanges(_:completionHandler:) exists. How come completionHandler closure is not declared as escaping, when changeBlock is declared as escaping?
Or more general question:
If I define a function with two closure parameters where the second closure is called after the first one is finished, and the first closure is escaping, does the second closure have to be escaping as well?
Generally, two closure parameters may be independent each other, so one is escaping and the other is non-escaping would be possible.How come completionHandler closure is not declared as escaping
But in this case, completionHandler is also escaping. In Swift (at least, in recent Swifts, I do not know where the clear documentation about this exists), Optional closure type is implicitly treated as escaping.
In fact, Xcode shows an error writing something like this:
Code Block func myFunc(_ completion: (Bool, Error?)->Void) { //<- non-escaping, non-Optional closure library.performChanges({ //... }, completionHandler: completion) //-> Passing non-escaping parameter 'completion' to function expecting an @escaping closure }
Two closure parameter may be independent. If you can assure that the second closure may only be called in the execution context of the method (meaning it may never executed after completion of the method) it has no need to be escaping.If I define a function with two closure parameters where the second closure is called after the first one is finished, and the first closure is escaping, does the second closure have to be escaping as well?
(Though, the second closure is called after the first one is finished and the second closure may only be called in the execution context of the method leads a conclusion that the first parameter also has no need to be escaping.)