[swift-evolution] [Idea] How to eliminate 'optional' protocol requirements
gwendal.roue at gmail.com
Sun Apr 10 07:30:11 CDT 2016
> Le 8 avr. 2016 à 14:47, Jonathan Hull via swift-evolution <swift-evolution at swift.org> a écrit :
> Interesting proposal, but I wanted to mention a couple of potential issues off the top of my head. I know when I was using optional requirements in Objective C, I would often use the presence/lack of the method (not just whether it returned nil) in the logic of my program. I used the presence of a method as a way for the implementor of a delegate to naturally communicate whether they wanted a more advanced feature. The absence of the method itself is information which can be utilized, not just whether it returns nil, and I believe that is part of what people are asking for when they say they want optional methods in Swift.
Couldn’t agree more.
An telling example is NSFetchedResultsControllerDelegate.controller(_:didChangeObject:atIndexPath:forChangeType:newIndexPath:).
When this method is not implemented, the NSFetchedResultsController does not have to perform the heavy computations of individual changes in a Core Data fetch request, since nobody is listening to them.
In today’s Swift, this lazy behavior requires an extra configuration flag.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution