Created
February 28, 2018 23:43
-
-
Save quocnb/1f4954057cac0086f9fe361aa755e70c to your computer and use it in GitHub Desktop.
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
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