I am trying to understand how to correctly swizzle using the method_setImplementation()
. So far online I have seen two predominantly popular ways to method swizzle, once is using method_setImplementation()
while the other levarages method_exchangeImplementation
.
When swizzling using method_exchangeImplementation()
you can get into an issue where a target class does not implement the method you are trying to swizzle. To avoid problems here with an ancestor class implementing the method and incorrectly swizzling that, you first add an implementation to your target class and then swap the swizzledMethod IMP
with your ancestor classes method to get things in order. This all makes perfect sense to me...
My question is how do we handle the same above case when swizzling with method_setImplementation
? Do we not have to handle this case (intuitively I feel like we do) ? If we do need to handle the above case sample code would help me greatly because I am lost as to how to handle it.