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

Viewed 628

The situation

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

An example

Imagine I have a class Collection and a descendant class List, which define—among other methods—an enumeration method in NSArray-style.

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

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

The question

Does this work (on all platforms) and does it conform with standards?

I would imagine it would work since the parameter list in the superclass method isn’t affected, while users of the subclass method would be aware (optionally with some type-casting) of the extra parameter.

1 Answers
Related