Skip to content

Instantly share code, notes, and snippets.

@danielctull
Created June 18, 2012 13:40
Show Gist options
  • Select an option

  • Save danielctull/2948427 to your computer and use it in GitHub Desktop.

Select an option

Save danielctull/2948427 to your computer and use it in GitHub Desktop.
A function to copy the class methods from one class to another
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