Skip to content

Instantly share code, notes, and snippets.

@st-small
Created January 24, 2020 09:43
Show Gist options
  • Save st-small/5be35810cbf98028cb02f2a1fb92be1b to your computer and use it in GitHub Desktop.
Save st-small/5be35810cbf98028cb02f2a1fb92be1b to your computer and use it in GitHub Desktop.
Swizzling
// 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