Created
June 8, 2020 18:26
-
-
Save MathVasc/af15fae904b78bbf475b9519a38319e0 to your computer and use it in GitHub Desktop.
SwizzleFunction
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
static func swizzle() { | |
let aClass: AnyClass? = object_getClass(SomeClass()) | |
let selector1: Selector = #selector(SomeClass.someMethod) | |
let selector2: Selector = #selector(SomeClass.someOtherMethod) | |
let method1: Method? = class_getInstanceMethod(aClass, selector1) | |
let method2: Method? = class_getInstanceMethod(aClass, selector2) | |
if let originalMethod = method1, let swizzledMethod = method2 { | |
method_exchangeImplementations(originalMethod, swizzledMethod) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment