facebook/xctool — pull request #256 by fpotter (2013-11-21 23:17:04+00:00)
Title: SwizzleGuard protects us from poorly behaved tests.

SwizzleGuard prevents poorly behaved tests from affecting the test
runner, otest-shim, and other tests. It gives us a way to reverse many
swizzling operations that were made during a test.

It works by interposing calls to the following Obj-C runtime functions:

- class_addMethod
- class_replaceMethod
- method_setImplementation
- method_exchangeImplementations

Whenever a method's implementation is swizzled, SwizzleGuard makes a
record of the original implementation (IMP). When the guard is
disabled, we restore the original implementation.

Most swizzling operations can be undone in this way. The only
exception is that we cannot remove a method that was added to class