Redefine makes easier to overwrite methods implementations during runtime using the objc runtime. It also makes possible to switch back and forth through implementations, the original and the new one. It uses the C++ concept of RAII, so the user just have to make sure to maintain a reference to the redefinition object for it to take place. When it is deallocated, everything goes back to normal.

The obvious use for it is unit tests. You don’t have to prepare your code specifically for tests using factories, interfaces and etc, since it’s possible to redefine any class or instance method. But, of course, you can do a lot of other crazy stuffs if you want to =D

Redefine on GitHub

Leave a comment