我用方法名定义协议(protocol)是:
- (id)initWithDelegate:(id <Foo>)delegate;
而在我的项目中,还有一个第三方协议(protocol)(在不同的类中):
- (id)initWithDelegate:(NSObject *)delegate;
在导入这两个协议(protocol)的另一个类中,我只使用第二种方法:
id thirdPartyObject = [[ThirdPartyClass alloc] initWithDelegate:self];
但 XCode 显示错误:self is not conform <Foo>
协议(protocol),而 self 不需要遵守该协议(protocol)。
如何避免这种命名冲突?
最佳答案
更改方法的名称。
- (id)initWithFooDelegate(id<Foo>)delegate;
关于iphone - 对象 : avoid protocol method name conflicts?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3252281/