Skip to content

Instantly share code, notes, and snippets.

@MathVasc
Created June 8, 2020 18:26
Show Gist options
  • Save MathVasc/af15fae904b78bbf475b9519a38319e0 to your computer and use it in GitHub Desktop.
Save MathVasc/af15fae904b78bbf475b9519a38319e0 to your computer and use it in GitHub Desktop.
SwizzleFunction
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