gpt4 book ai didi

iphone - 需要/想要将 NSError** 作为参数传递给 performSelector

转载 作者:搜寻专家 更新时间:2023-10-30 19:50:50 25 4
gpt4 key购买 nike

我想调用一个方法的选择器,该方法具有通常的 NSError** 参数:

-(int) getItemsSince:(NSDate *)when dataSelector:(SEL)getDataSelector error:(NSError**)outError  {
NSArray *data = nil;
if([service respondsToSelector:getDataSelector]) {
data = [service performSelector:getDataSelector withObject:when withObject:outError];
// etc.

...编译器不喜欢的:

warning: passing argument 3 of 'performSelector:withObject:withObject:' from incompatible pointer type

除了将指针封装在对象中之外,有什么办法可以解决这个问题吗?

最佳答案

查看 NSInvocation ,它可以让您以更灵活的方式“执行选择器”。

这里有一些代码可以帮助您入门:

if ([service respondsToSelector:getDataSelector]) {
NSArray *data;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[service methodSignatureForSelector:getDataSelector]];
[invocation setTarget:delegate];
[invocation setSelector:getDataSelector];
// Note: Indexes 0 and 1 correspond to the implicit arguments self and _cmd,
// which are set using setTarget and setSelector.
[invocation setArgument:when atIndex:2];
[invocation setArgument:outError atIndex:3];
[invocation invoke];
[invocation getReturnValue:&data];
}

关于iphone - 需要/想要将 NSError** 作为参数传递给 performSelector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/889998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com