Posts

Showing posts from April, 2017

Method Swizzling - Objective C hackery

Image
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.

Simple fun with Closures

Image
So closures are self contained blocks of functionality which can be passed around and reused in various parts of your code. Closures are similar to lambda's in other languages.. A typical use case for employing closures is in iOS Grand Central Dispatch You can find a more detailed explanation here https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-ID94