Skip to content

Instantly share code, notes, and snippets.

@zonble
Created August 29, 2013 04:21
Show Gist options
  • Select an option

  • Save zonble/6374245 to your computer and use it in GitHub Desktop.

Select an option

Save zonble/6374245 to your computer and use it in GitHub Desktop.
How to remove Objective-C instance methods
#import <Foundation/Foundation.h>
void removeInstanceMethod(Class cls, SEL _cmd);
#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];
}
@songxing10000
Copy link
Copy Markdown

Interesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment