Can a subclass add parameters to a block in a parameter in an inherited method?

Situation

A superclass defines a method, and a subclass overrides this method. The only difference is that the subclass adds the parameter to the block, which itself is the parameter of the method.

Example

Imagine that I have a class Collectionand a class of descendants Listthat define, among other methods, an enumeration method in style NSArray.

@interface Collection : NSObject
- (void)enumerateObjectsUsingBlock: (void (^)(id obj))block;
@end

@interface List : Collection
- (void)enumerateObjectsUsingBlock: (void (^)(id obj, int index))block;
@end

Question

Does it work (on all platforms) and is it up to standard?

I would suggest that this would work, since the list of parameters in the superclass method would not be affected, while users of the subclass method would know (not necessarily with some type) an additional parameter.

+4
1

; , .

:

, . Objective-C - ( instancetype). , .

, , , , , (a), (a, b) , (a,b.c), (a,b,c,d) .., . fun(a,b,c,d), fun fun(a) , , .

+7

All Articles