Last active
August 29, 2015 13:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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