What needs to be done for one method in several protocols? (Goal C)

Say I have ProA and ProB protocols. They both have a method - (void) testingMethod;

And I have another ClassAB class that implements both of these protocols. What should I do for the testMethod method?

I know that we can implement only one testing method. But what should I do if I want to have two test methods in the ClassAB class for ProA and Prob, respectively?

+4
source share
3 answers

There is also a case where you simply use two libraries that define protocols with methods that have the same name as a match, so you cannot change them.
In this case, you will need to create two classes, each of which implements each protocol, say ClassA for ProA and ClassB for ProB , and then pass your instance of ClassAB for each of them.
When ClassA receives a call from testingMethod you call a call to the ClassAB method, for example classAB testingMethodA .

If this is not clear, tell me and I am writing an implementation.

+3
source

you must separate the general protocol method in another protocol and create two new protocols that implement the earlier protocol .. see this very well explained here. fooobar.com/questions/900679 / ...

+2
source

Just rename the method in the first protocol to testMethod1 and the method in the second protocol to testMethod2

+1
source

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


All Articles