Skip to content

Instantly share code, notes, and snippets.

@armadsen
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save armadsen/8814186 to your computer and use it in GitHub Desktop.

Select an option

Save armadsen/8814186 to your computer and use it in GitHub Desktop.
Simple test program demonstrating use of NSInvocation to get CGMutablePathRef property by name
/* Compile and run like so:
$> clang CGMutablePathRef_NSInvocation.m -ObjC -std=c99 -fobjc-arc -framework Foundation -framework CoreGraphics
$> ./a.out
*/
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@interface TestClass : NSObject
@property CGMutablePathRef path;
@end
@implementation TestClass
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
CGMutablePathRef path = CGPathCreateMutable();
TestClass *test = [TestClass new];
test.path = path;
NSLog(@"Original Path: %p", path);
SEL selector = NSSelectorFromString(@"path");
NSMethodSignature *signature = [test methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
[invocation setTarget:test];
[invocation invoke];
CGMutablePathRef result = NULL;
[invocation getReturnValue:&result];
NSLog(@"Result: %p", result);
CGPathRelease(path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment