swizzle

How to swizzle init in Swift

时光总嘲笑我的痴心妄想 提交于 2019-12-18 13:40:45
问题 I'm following Swift & the Objective-C Runtime, it works for normal methods. I like to swizzle init method, from my understanding, init is like a class method. So I tried swizzling init as instance and class method. But it does not seem to work I can make it work using Objective C, just wonder how to make it work in Swift Excerpted from my gist dispatch_once(&Static.token) { let originalSelector = Selector("init:source:destination:") let swizzledSelector = Selector("ftg_init:source:destination

How to swizzle init in Swift

徘徊边缘 提交于 2019-11-30 10:50:53
I'm following Swift & the Objective-C Runtime , it works for normal methods. I like to swizzle init method, from my understanding, init is like a class method. So I tried swizzling init as instance and class method. But it does not seem to work I can make it work using Objective C, just wonder how to make it work in Swift Excerpted from my gist dispatch_once(&Static.token) { let originalSelector = Selector("init:source:destination:") let swizzledSelector = Selector("ftg_init:source:destination:") let originalMethod = class_getClassMethod(self, originalSelector) let swizzledMethod = class