-
-
Save grp/3074235 to your computer and use it in GitHub Desktop.
Swizzletastic
This file contains 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
#include <objc/runtime.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include "SwizzleMyNizzleProtocol.h" | |
IMP SwizzleMethod(Class _class, SEL sel, IMP imp) { | |
if (_class == nil || sel == NULL || imp == NULL) | |
return NULL; | |
Method method = class_getInstanceMethod(_class, sel); | |
if (method == nil) | |
return NULL; | |
unsigned int count; | |
Method *methods = class_copyMethodList(_class, &count); | |
for (unsigned int index = 0; index < count; index++) | |
if (methods[index] == method) { | |
free(methods); | |
return method_setImplementation(method, imp); | |
} | |
} | |
free(methods); | |
class_addMethod(_class, sel, imp, method_getTypeEncoding(method)); | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment