Created
December 14, 2016 15:10
-
-
Save PaulTaykalo/d287b30d353f9ddfd5eb8b0f15fdc41a to your computer and use it in GitHub Desktop.
Objectvive-C Runtime and typedef
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
| @interface Item : NSObject @end | |
| @implementation Item @end | |
| typedef NSArray<Item *> Items; | |
| @interface Cooler : NSObject | |
| - (id)updateItems:(Items *)items; | |
| - (id)updateItems2:(NSArray<Item *> *)items; | |
| @end | |
| @implementation Cooler | |
| - (id)updateItems:(Items *)items { return nil; } | |
| - (id)updateItems2:(NSArray<Item *> *)items { return nil; } | |
| @end | |
| #import <objc/runtime.h> | |
| void DumpObjcMethods(Class clz) { | |
| unsigned int methodCount = 0; | |
| Method *methods = class_copyMethodList(clz, &methodCount); | |
| printf("Found %d methods on '%s'\n", methodCount, class_getName(clz)); | |
| for (unsigned int i = 0; i < methodCount; i++) { | |
| Method method = methods[i]; | |
| printf("\t'%s' has method named '%s' of encoding '%s'\n", | |
| class_getName(clz), | |
| sel_getName(method_getName(method)), | |
| method_getTypeEncoding(method)); | |
| } | |
| free(methods); | |
| } | |
| int main(int argc, char * argv[]) { | |
| @autoreleasepool { | |
| DumpObjcMethods([Cooler class]); | |
| return 0; | |
| } | |
| } | |
| /// OUTPUT: is | |
| /// Found 2 methods on 'Cooler' | |
| /// 'Cooler' has method named 'updateItems:' of encoding '@24@0:8^{NSArray=#}16' | |
| /// 'Cooler' has method named 'updateItems2:' of encoding '@24@0:8@16' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment