Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save victorpanitz/6094ce0585eac0f4d67af9c22e602a9c to your computer and use it in GitHub Desktop.
Save victorpanitz/6094ce0585eac0f4d67af9c22e602a9c to your computer and use it in GitHub Desktop.
extension URLSession {
class func initSwizzle() throws {
typealias ResultBlock = (@escaping ([URLSessionTask]) -> Void) -> Void
let original = #selector((URLSession.getAllTasks(completionHandler:)) as (URLSession) -> ResultBlock)
let swizzled = #selector((FakeURLSession._getAllTasks(completionHandler:)) as (FakeURLSession) -> ResultBlock)
guard
let originalMethod = class_getInstanceMethod(URLSession.self, original),
let swizzledMethod = class_getInstanceMethod(FakeURLSession.self, swizzled)
else { return }
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment