Created
August 29, 2013 04:21
-
-
Save zonble/6374245 to your computer and use it in GitHub Desktop.
How to remove Objective-C instance methods
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
| #import <Foundation/Foundation.h> | |
| void removeInstanceMethod(Class cls, SEL _cmd); |
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
| #import "MethodRemoval.h" | |
| #import <objc/runtime.h> | |
| static void doesNotRecognizeSelector(id object, SEL _cmd); | |
| void removeInstanceMethod(Class cls, SEL _cmd) { | |
| NSCParameterAssert(cls != NULL); | |
| NSCParameterAssert(_cmd != NULL); | |
| Method m = class_getInstanceMethod(cls, _cmd); | |
| NSCAssert(m != NULL, @"We must have the instance method."); | |
| method_setImplementation(m, (IMP)doesNotRecognizeSelector); | |
| } | |
| void doesNotRecognizeSelector(id object, SEL _cmd) { | |
| [object doesNotRecognizeSelector:_cmd]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting