考虑到 invokeBlockWithArgs:
要求参数以 nil 结尾,有什么方法可以调用以 nil
作为给定参数的 block 吗?
模拟对象中的示例方法定义:
- (void)methodWithCompletion:(void(^)(NSString*, NSError* )) completionBlock;
给定的模拟对象应该调用:
completionBlock(@"foo", nil);
但是,使用invokeBlockWithArgs
:
OCMStub([mockObj methodWithCompletion:([OCMArg invokeBlockWithArgs:@"foo", nil, nil])]);
方法失败,参数太少;显然,以 nil 为终止符,它无法识别 block 的第二个参数应该是 nil
。
最佳答案
我还没有测试过它,但理论上传递 [NSNull null]
应该可以。
关于ocmock 的 invokeBlockWithArgs 使用 nil 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38731170/