we can swizzle methods in swift as follows
let selectorfirst = #selector(ClassName.function(_:))
let swizzledFunction = #selector(ClassName.function2(_:))
let method1 = class_getInstanceMethod(ClassInstance, selectorfirst)
let method2 = class_getInstanceMethod(ClassInstance, swizzledFunction)
method_exchangeImplementations(method1, method2)
//try like this using subclass
class URLSessionSubClass: URLSession {
static var sharedInstance: URLSessionSubClass?
static func getSharedInstance() -> URLSessionSubClass {
if sharedInstance == nil {
sharedInstance = URLSessionSubClass()
let selectorfirst = #selector(URLSessionSubClass.function(_:))
let swizzledFunction = #selector(URLSessionSubClass.function2(_:))
let method1 = class_getInstanceMethod(self, selectorfirst)
let method2 = class_getInstanceMethod(self, swizzledFunction)
method_exchangeImplementations(method1, method2)
}
return sharedInstance!
}
}