Skip to content

Instantly share code, notes, and snippets.

@mavris
Created July 2, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavris/dd3502c08e196d2b00264cca007af042 to your computer and use it in GitHub Desktop.
Save mavris/dd3502c08e196d2b00264cca007af042 to your computer and use it in GitHub Desktop.
BOOL isMethodExists = !class_addMethod([self class], defaultSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (isMethodExists) {
method_exchangeImplementations(defaultMethod, swizzledMethod);
}
else {
class_replaceMethod([self class], swizzledSelector, method_getImplementation(defaultMethod), method_getTypeEncoding(defaultMethod));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment