[Discussion] Enforcing Calling Super

(Thorsten Seitz) #1


It depends what you mean by “strong”. Sure, a log statement won’t make much difference. But the examples I gave do have semantic requirements that super should either go first or last in performing real work to be done by the method.

For instance:

> // If you override this method, you must call super first to get the invalidation context object to return. After getting this object, set any custom properties and return it.
> func invalidationContextForBoundsChange(_ newBounds: CGRect) -> UICollectionViewLayoutInvalidationContext

Why must I call super first ? Why can’t I don’t a bunch of things that are related to my subclass first ?

How am I supposed to do if I want to compute a new bound to pass to super instead of forwarding it naively.

ditto for

> // call super first to retrieve the item’s existing attributes and then make your changes to the returned structure.
> layoutAttributesForInteractivelyMovingItemAtIndexPath(_ indexPath: NSIndexPath, withTargetPosition position: CGPoint) -> UICollectionViewLayoutAttributes

Why would you prevent a subclass to compute an other indexPath or target position before calling super ?


These are excellent examples demonstrating why enforcing super(first/last) is too restrictive.



Am 25. Februar 2016 um 21:13 schrieb Jean-Daniel Dupas via swift-evolution swift-evolution@swift.org:

Le 25 févr. 2016 à 20:28, Matthew Johnson matthew@anandabits.com a écrit :