Excellent article, taming TavleViewControllers (and really ViewControllers in general) can be quite the challenge without a plan to keep things organized.
I will however leave one warning about putting too much logic in the view itself, especially binding logic (code that links a property from the model to the view) or business logic. Apple intentionally designed the Cocoa Touch framework to have exceptionally dumb views, and if you spend some time looking at their own views, you’ll notice that their views ONLY do actual layout logic. You specify each property individually, not by passing a model to the view, and the view’s only job is to manage where everything shows up at different screen sizes. Even detailed user interaction logic is usually better off in a gesture recognizer, at the controller level (not necessarily in the controller itself). Views know nothing about their data source, including what format the data is stored in or where it came from. Not all MVC systems use this approach, but Apple’s does and it WILL bite you if you don’t do things their way (most of the time 😀)
UIKit and Swift are both “Delegate Oriented,” and you’ll get lots of help from the framework and language if you leverage this. Delegates aren’t limited to reacting to events, they can also be wonderful for reusable, customizable (and reactive) configuration. When you find yourself doing detailed view configuration in a controller, don’t move that into the view, because views are supposed to allow detailed configuration, and you don’t want to abstract that out of existence. Instead, create a delegate that your view controller will call, which creates, configures, and returns the view. This sounds a lot like UITableViewDataSource…. This approach will let you create lots of small delegate objects that live outside the view controller, can be used in different contexts with different controllers and views, and can be swapped out dynamically without modifying the view controller itself. There’s no need to reinvent the wheel on this, but we do need to use the wheel as it was intended, which does not involve making your view controller conform to every protocol in existence and creating a monster monolith.
