Skip to content

Instantly share code, notes, and snippets.

@sanllier
Last active March 22, 2018 18:19
Show Gist options
  • Save sanllier/386349d81e8b2c0aaf00f0e70f76bce3 to your computer and use it in GitHub Desktop.
Save sanllier/386349d81e8b2c0aaf00f0e70f76bce3 to your computer and use it in GitHub Desktop.
@objc func veryUsefulMethod() {
guard let superclass = superclass else { return }
let objcSelector = Selector("veryUsefulMethod")
typealias CFunction = @convention(c) (AnyObject, Selector) -> Void
let impl = class_getMethodImplementation(superclass, objcSelector)
let callableImpl = unsafeBitCast(impl, to: CFunction.self)
callableImpl(self, objcSelector)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment