Created
August 16, 2020 21:51
-
-
Save victorpanitz/6094ce0585eac0f4d67af9c22e602a9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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