Compiler got confused about layout

I am using OCMock to assist with testing developed for iPad apps using Xcode. I have a test code:

id mock = [OCMockObject mockForProtocol:@protocol(SomeProtocol)];
Vector direction = { 1.0f, 2.0f, 3.0f };
[[mock expect] setDirection:direction];

      

When I try to compile I get warnings and errors like this:

warning: multiple methods named 'setDirection:' found

error: sending 'Vector' to parameter of incompatible type
 'UISwipeGestureRecognizerDirection' (aka 'enum UISwipeGestureRecognizerDirection')

Obviously, the compiler cannot determine what type of object the layout should be. I'm not sure how to specify that it should deal with the setDirection method from the SomeProtocol protocol instead of the setDirection method from another class.

What can you do to successfully create a test case like this assembly?

+3
ocmock


source to share


2 answers


By ditching the layout with the act, it will remove the ambiguity:



[(id<SomeProtocol>)[mock expect] setDirection:direction];

      

+6


source to share


For modern OCMock 3 syntax:



id protocolMock = OCMProtocolMock(@protocol(MYProtocol));
OCMExpect([(id <MYProtocol>)protocolMock ambiguousMethod]);

      

+2


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics