Created
February 13, 2017 18:00
-
-
Save sundeepgupta/16b64c00eb06583ccc4a6cbc9f492f77 to your computer and use it in GitHub Desktop.
Swift 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
extension TheClass { | |
class func swizzle(_ original: Selector, with swizzled: Selector, for klass: AnyClass) { | |
let originalMethod = class_getInstanceMethod(klass, original) | |
let swizzledMethod = class_getInstanceMethod(klass, swizzled) | |
method_exchangeImplementations(originalMethod, swizzledMethod) | |
} | |
func swizzle(_ original: Selector, with swizzled: Selector) { | |
let klass: AnyClass! = object_getClass(self) | |
DispatchQueue.swizzle(original, with: swizzled, for: klass) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment