i'm a new user of OCMock, so maybe i'm just missing something simple here. this code does not compile:
id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]];
[[mockSession expect] addOutput:[OCMArg anyPointer]];
the error is
Multiple methods named 'addOutput:' found with mismatched result, parameter type or attributes
the signature of the method addOutput on AVCaptureSession is as follows
- (void)addOutput:(AVCaptureOutput *)output
as far as i can tell, the problem is that the method addOutput exists on both the AVCaptureSession and AVAssetReader classes. the method signature for addOutput on AVAssetReader is as follows.
- (void)addOutput:(AVAssetReaderOutput *)output
apparently the compiler thinks my mockSession is an AVAssetReader, but i don't know why it chooses that class instead of AVCaptureSession. if i expect a different method on AVCaptureSession that does not exist on AVAssetReader, then it compiles. i have tried the following without success. it compiles, but crashes.
id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]];
[(AVCaptureSession*)[mockSession expect] addOutput:[OCMArg anyPointer]];
this code also does not compile, with the same error as the previous one
id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]];
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[[mockSession expect] addOutput:output];
any guidance here?
In cases where your variable is an "id" but a method is declared with different signatures in different classes you should help the compiler by casting the object to the correct type, e.g.
[((AVCaptureSession *)[mockSession expect]) addOutput:[OCMArg any]];
In either case, if the argument is an object, as it seems in your case, you should use any and not anyPointer. But you figured that one out already. ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With