But in the particular case with UINavigationController, there was no way of executing code after removing the ViewController. This presented a big problem, because I would either have to time the removal properly, or find a hacky way of synching the animation end and the code execution start:

This provided just the functionality I needed! Start a CoreAnimation (CA) transaction, set a completion block which executes after the transaction is done, and then execute the code to remove the ViewController from the stack.

Now the interesting bit here, is that, if not for extensions, I would have had to copy this code over and over. Instead, I was able to create a new extension to UINavigationController that contains the functionality, much in the same way as Apple's APIs:

And there we go, this extension provides just the functionality we need, without hacking, and even using the original functionality Apple provided.

Swift Tuples

Another nice feature in Swift are tuples. They are a group of values, represented by one value. It can be thought of as helper structs you make that are used as return types for functions. And this is exactly how they help out, the quick creation of a group of values that are related, but don't need a specific class to represent them.

func performAction() -> (bool, string?) {
return (true, "Success")
}

There is another great usage for them, switch statements. Remember those times when you had nested switches? Instead, you can use something like this: