Skip to content

Instantly share code, notes, and snippets.

@sanllier
Created March 23, 2018 17:56
Show Gist options
  • Save sanllier/08551f5678dd0d0add20e2fbaf367eec to your computer and use it in GitHub Desktop.
Save sanllier/08551f5678dd0d0add20e2fbaf367eec to your computer and use it in GitHub Desktop.
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