I'm aware standard delegate method declaration should include the object that triggers the method, usually of the class that declared the protocol.

That's fine when the delegate method includes further arguments down the line, but what if it doesn't?


@protocol MyObjectDelegate <NSObject>

- (void)myObject:(id)object didPerformActionWithResult:(NSObject*)resul;
- (void)myObject:(id)object didPerformActionWithoutResult;

I know the second method isn't accepted, its missing an argument, but what do I put there? A BOOL that I know will always be true?

Do I change |didPerformActionWithoutResult| to performedAction:(BOOL)yesOrNo?

Or move the object reference to the end?


Have a look at TableView's datasource protocol:

– tableView:cellForRowAtIndexPath:
– numberOfSectionsInTableView:
– tableView:numberOfRowsInSection:
– sectionIndexTitlesForTableView:

I find it quite hard to come up with nice names for such sidle parameter method signature and code completion would be easier, if the form, you propose would exists, but if a method accepts parameters, it name must terminate with one of therm — if it just have one, it must be at the end.

Your idea of adding a dead parameter is IMO very bad design. Another parameter should lead possibly to another behavior. Also it would work against objective-c strength of self explaining method name. countOfSubscribersForNewsEmitter:(MyNewsEmitter *)emitter make sense, while newsEmitter:(MyNewsEmitter *)emitter countOfSubscribers:(BOOL) aBool does not make much sense, as the bool disallows us to form a correct mental model of the purpose of this method.

  • \$\begingroup\$ Seconded. Copy Apple's naming conventions like this one so your code is easier to understand and fits with the rest of the API. :) There's no great answer to this question, so What Apple Did is the best solution. \$\endgroup\$ – andyvn22 Apr 26 '12 at 2:08

This might indeed be confusing at first. The solution is to put the calling object as the only and last argument of the method. The second delegate method would then look like the one below.

- (void)myObjectDidPerformActionWithoutResult:(id)object;
- (void)actionPerformedWithoutResultByObject:(id)object;

might be another alternative.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.