2

I need to add some methods to the delegate protocol of my custom UITextField subclass. So I put this in the header:

@protocol MyTextFieldDelegate (UITextFieldDelegate)
- (void)textfieldDidSomething:(UITextField*)textField;
@end

Is this fine?

openfrog
  • 40,201
  • 65
  • 225
  • 373
  • 1
    See [How to extend protocols / delegates in Objective-C](http://stackoverflow.com/questions/732701/how-to-extend-protocols-delegates-in-objective-c) – BoltClock Sep 27 '10 at 11:29

2 Answers2

3

In principle I think it looks fine. The only point I would make is I would write something like:

@protocol MyTextFieldDelegate (MyTextFieldDelegateExtras)
- (void)textfieldDidSomething:(UITextField*)textField;
@end

to distinguish it from the methods defined in the UITextFieldDelegate protocol.

But really if you want to extend the protocol, then use:

@protocol MyTextFieldDelegate <UITextFieldDelegate>
- (void)textfieldDidSomething:(UITextField*)textField;
@end
petert
  • 6,672
  • 3
  • 38
  • 46
1

also when adding categories its suggested to add it in as a separate file with the naming convention of MyTextFieldDelegate+MyTextFieldDelegateExtras.h

vince
  • 21
  • 1