objective-cruntimeswizzle

objective-c override system method


I find a c++ system method causes crash in ios and I try to swizzle the method. However, I do not how to do that because it's a method of a c++ class. Anyone know whether can I do that?


Solution

  • Method swizzling is unique to objective-c (and even there one has to use it carefully), and is not applicable to c++.

    I suppose that you don't have access to the source code of the c++ class. Then the only way to "exchange" the implementation of a method at a specific c++-class is to derive a subclass, override the method, and then make sure that the subclass is used instead of the other class. It is still unlikely that you have a chance; the method being not virtual, the class to be replaced being used in non-polymorphic ways, the class to be replaced already having several subclasses, each of these points will prevent you from being successful.

    Good luck though!