I want to call a method selector that has the usual argument 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.
... which the compiler does not like:
warning: passing argument 3 of 'performSelector:withObject:withObject:' from incompatible pointer type
Is there any way around this to not encapsulate the pointer in the object?
Check NSInvocation , which allows you to “make selections” in a more flexible way.
Here is the code to get you started:
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]; }
NSError ** - (id), Selector withObject. NSInvocation, , , . , NSError ** , performSelector (, , , ?)
, NSInvocation -performSelector:withObject:withObject. NSInvocation void*, / , , .
NSInvocation
-performSelector:withObject:withObject
void*
, performSelector:, , , , .
performSelector:
Source: https://habr.com/ru/post/1708773/More articles:In Visual Studio, can I disable my application signing when debugging? - .netRun sgml-pretty-print when opening xml file in emacs? - emacsМогу ли я захватить предупреждение "Unrecognized escape" при компиляции регулярного выражения? - regexGoogle Maps tiles - how to divide 30 thousand coordinates into tiles - mapsJam when solving the minimum pairing problem - algorithmThe problem of stretching a text field - cssSetting TextBox.Width = "*" through the code - wpfSQL Server datetime datatype does not allow many formats - datetimeWindsor Castle: - Injection interface dictionary through configuration - c #How can I create one autotools project against another autotoolset project that is not installed? - build-processAll Articles