Created
June 18, 2012 13:40
-
-
Save danielctull/2948427 to your computer and use it in GitHub Desktop.
A function to copy the class methods from one class to another
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
| void copyClassMethods(Class existingClass, Class class) { | |
| NSUInteger classMethodsCount; | |
| Method *classMethods = class_copyMethodList(object_getClass(existingClass), &classMethodsCount); | |
| for (int i = 0; i < classMethodsCount; i++) { | |
| Method method = classMethods[i]; | |
| SEL selector = method_getName(method); | |
| IMP implementation = method_getImplementation(method); | |
| const char *types = method_getTypeEncoding(method); | |
| class_addMethod(object_getClass(class), selector, implementation, types); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment