3 ms·
> The easiest way to swizzle something is just to make a category on NSObject and call method_exchangeImplementations in +load. Don't do this, declaring a meth
by saagarjha 7y ago
> The easiest way to swizzle something is just to make a category on NSObject and call method_exchangeImplementations in +load.
Don't do this, declaring a method in a category with the same name as an already existing method is undefined behavior. Use a static constructor instead.
- lilyball 7y agoThe article isn't relying on method name conflict in the category. It's declaring a new method and swizzling in +load. If you meant the +load method itself conflicts, that's not true because +load on categories is handled specially by the Obj-C runtime. You can have 20 different categories define +load on the same class and the runtime will invoke all of them.
- saagarjha 7y agoOh, TIL!