Method Swizzling - Objective C hackery

This is a new concept to me and it's quite arguably a feature that could haunt you the more your iOS app gets more complex. Objective C Method Swizzling is the process of changing the reference your method selector points to at runtime.


It is made possible by Objective C's dispatch model. So let's say a method has a reference f(). In method swizzling you can point the method f() to another method at runtime. A simple example Lets say we wish to print a log statement whenever viewDidAppear() is called on a UIViewController. One solution could be to subclass UIViewController with a LoggingViewController and use that as our new base class for view controllers.

Comments

Popular posts from this blog

Java 8 features

Simple fun with Closures

Creating a CardView View in your iOS App