Skip to content

Instantly share code, notes, and snippets.

@quocnb
Created February 28, 2018 23:43
Show Gist options
  • Save quocnb/1f4954057cac0086f9fe361aa755e70c to your computer and use it in GitHub Desktop.
Save quocnb/1f4954057cac0086f9fe361aa755e70c to your computer and use it in GitHub Desktop.
private let swizzling: (AnyClass, Selector, Selector) -> () = { forClass, originalSelector, swizzledSelector in
let originalMethod = class_getInstanceMethod(forClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector)
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}
extension UIViewController {
static let swizzled: Void = {
let originalSelector = #selector(viewDidLoad)
let swizzledSelector = #selector(swizzled_viewDidload)
swizzling(UIViewController.self, originalSelector, swizzledSelector)
}()
@objc func swizzled_viewDidload() {
swizzled_viewDidload()
print("view did load at" + String(self.description))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment