Slide 13
Slide 13 text
Method SwizzlingͰϞοΫ༻ͷURLProtocol
ʹࠩ͠ସ͑
public extension URLSessionConfiguration {
public class func setup() {
let `default` = class_getClassMethod(URLSessionConfiguration.self,
#selector(getter: URLSessionConfiguration.default))
let swizzled = class_getClassMethod(URLSessionConfiguration.self,
#selector(getter: URLSessionConfiguration.mock))
method_exchangeImplementations(`default`, swizzled)
}
private dynamic class var mock: URLSessionConfiguration {
let configuration = self.mock
configuration.protocolClasses?.insert(MockURLProtocol.self, at: 0)
URLProtocol.registerClass(MockURLProtocol.self)
return configuration
}
}