Closure in Swift: A reminder on how awesome they are.

I was re-reading Apple’s documentation about closure and I tough it couldn’t hurt anybody to share this little resume about closure syntax.

Here’s a simple closure :

Here’s the same but simpler :

Hmm even simpler :

Huh ?!? Even more :

WTF ?!?! Really ?! (but yeah it works) :

And finally (unreadable but still) :

From The Swift Programming Language (Swift 3.0.1)



UIViewController extension for child view controller containment.

Hello !  I know its been a while, holidays and all …

Here’s a little extension that does no magic but shortens your code if you have to load child view controller from storyboards.  Sorry for the lack of syntax colouring, WordPress does not seem to support Swift yet.

[code language=”text”]
import Foundation

typealias ViewControllerStoryboardInfo = (name: String, id: String?)

protocol Container {

extension Container where Self: UIViewController {

func addChildViewController(withInfo info: ViewControllerStoryboardInfo)-> UIViewController? {

var viewController: UIViewController! = nil

switch {
case let identifier where identifier != nil:
viewController = UIStoryboard(name:, bundle: nil).instantiateViewController(withIdentifier: identifier!)
viewController = UIStoryboard(name:, bundle: nil).instantiateInitialViewController()

if let viewController = viewController {

viewController.view.frame = self.view.bounds
viewController.didMove(toParentViewController: self)
return viewController

return nil

func removeAllChildViewController() {
self.childViewControllers.forEach({ (controller) in
controller.willMove(toParentViewController: nil)