Created
March 23, 2018 17:56
-
-
Save sanllier/08551f5678dd0d0add20e2fbaf367eec to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UIView { | |
static let swizzle: Void = { | |
let originalSelector = #selector(layoutSubviews) | |
let swizzledSelector = #selector(swizzled_layoutSubviews) | |
guard let originalMethod = class_getInstanceMethod(UIView.self, originalSelector) else { return } | |
guard let swizzledMethod = class_getInstanceMethod(UIView.self, swizzledSelector) else { return } | |
method_exchangeImplementations(originalMethod, swizzledMethod) | |
}() | |
@objc func swizzled_layoutSubviews() { | |
swizzled_layoutSubviews() | |
// do stuff | |
} | |
} | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
override init() { | |
super.init() | |
UIView.swizzle | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment