Objc: avoid method method name conflicts?

I define a protocol with a method name:

   - (id)initWithDelegate:(id <Foo>)delegate;

My project also has a third-party protocol (in different classes):

   - (id)initWithDelegate:(NSObject *)delegate;

In another class that imports both protocols, I just use the second method:

id thirdPartyObject = [[ThirdPartyClass alloc] initWithDelegate:self];

but Xcode displays an error: self does not match <Foo>, and itself does not have to conform to this protocol.

How to avoid name conflict?

+3
source share
2 answers

Change the name of the method.

- (id)initWithFooDelegate(id<Foo>)delegate;
+5
source

I am not 100% sure if I understand what you are doing, but I think the problem is that you are trying to use covariant methods in a C object (methods with the same selector name, but differently typed arguments).

, , , , , , o , , , , initWithDelegate: , (, , , , ). , . Apple , .

.

+4

Source: https://habr.com/ru/post/1754734/


All Articles