Created
January 24, 2020 09:43
-
-
Save st-small/5be35810cbf98028cb02f2a1fb92be1b to your computer and use it in GitHub Desktop.
Swizzling
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
// Swizzling | |
extension NSObject { | |
class func swizzleMethods(origSelector: Selector, withSelector: Selector, | |
forClass: AnyClass) { | |
let originalMethod = class_getInstanceMethod(forClass, origSelector) | |
let swizzledMethod = class_getInstanceMethod(forClass, withSelector) | |
method_exchangeImplementations(originalMethod!, swizzledMethod!) | |
} | |
func swizzleMethods(origSelector: Selector, withSelector: Selector) { | |
let aClass: AnyClass! = object_getClass(self) | |
NSObject.swizzleMethods(origSelector: origSelector, withSelector: withSelector, forClass: aClass) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment