Saturday, May 11, 2013

NSInvocation getReturnValue example ios


getReturnValue:

Gets the receiver's return value.
- (void)getReturnValue:(void *)buffer
Parameters
buffer
An untyped buffer into which the receiver copies its return value. It should be large enough to accommodate the value. See the discussion below for more information about buffer.
Discussion( NSInvocation getReturnValue example )
Use the NSMethodSignature method methodReturnLength to determine the size needed for buffer:
NSUInteger length = [[myInvocation methodSignature] methodReturnLength];
buffer = (void *)malloc(length);
[invocation getReturnValue :buffer];
When the return value is an object, pass a pointer to the variable (or memory) into which the object should be placed:
id anObject;
NSArray *anArray;
[invocation1 getReturnValue:&anObject];
[invocation2 getReturnValue:&anArray];
If the NSInvocation object has never been invoked, the result of this method is undefined.
( NSInvocation getReturnValue example )
@interface NSInvocation (ObjectReturnValue)

- (id)objectReturnValue;

@end

@implementation NSInvocation (ObjectReturnValue)

- (id)objectReturnValue {
    __unsafe_unretained id result;
    [self getReturnValue:&result];
    return result;
}

@end
( NSInvocation getReturnValue example )
CFTypeRef result;
[anInvocationTMP invoke];
[anInvocationTMP getReturnValue:&result];
if (result)
    CFRetain(result);
UIButton *pushButton5 = (__bridge_transfer UIButton *)result;