In Objective-C, how can I make a typedef for a composed object?

443 Views Asked by At

I'm using OCMProtocolMock to mock a protocol. After some clean up, my object conforms to 3 protocols:

id<MyProtocolA, MyProtocolB, MyProtocolC>

OCMProtocolMock takes only 1 arg, so I'd like to make a typedef of my new, composed object to pass to OCMProtocolMock.

Something like:

typedef id<MyProtocolA, MyProtocolB, MyProtocolC> CombinedProtocol;

id<CombinedProtocol> _myCombinedObject = OCMProtocolMock(@protocol(CombinedProtocol));

But that's throwing compiler error saying that it cannot find the protocol declaration for 'CombinedProtocol'.

Any ideas? Thanks!

1

There are 1 best solutions below

0
h.and.h On

A possible solution is to just define a protocol that conforms to all the others.

@protocol CombinedProtocol <MyProtocolA, MyProtocolB, MyProtocolC>

@end

And just use that like so

id<CombinedProtocol> _myCombinedObject = OCMProtocolMock(@protocol(CombinedProtocol));

And ignore the typedef entirely