开发者

Is it possible to extend an protocol like this?

开发者 https://www.devze.com 2023-01-17 13:54 出处:网络
I need to add some methods to the delegate protocol of my custom UITextField subclass. So I put this in the header:

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)textfieldDi开发者_如何学PythondSomething:(UITextField*)textField;
@end

Is this fine?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消