Monthly Archives: April 2015

My Quest to Skinnier ViewControllers

Fat ViewControllers are a pain in the rear. So I have been researching different solutions to cope with the problem. There are different approaches batteling this, but none of the solutions I have found are exactly what Im looking for. VIPER is one approach, but its architecture is too fragmented, a project built with this paradigm gives you a lot of small classes and extensions, making the Xcode project a jungle of goups and small files, and adding an extra layer of complexity. For some this is just what they are looking for, but for me its not. Chris Eidhof has also a really interesting approach with intentions. I tried this but so far I have not gotten it to work for me the way I wanted. So because I write Swift in active projects, I needed an approach I was comfortable with, and found in the Ray Wenderlich Swift Style Guide.

The easiest way is to show this in code.

How I used to do it

Ray Wenderlich Style Sheet

My form of skinny ViewControllers

Instead of showing everything into one single file, I ended up with putting each of the extensions into seperate files, using a really simple naming convention. I have the UIViewController, MainVC, in a ViewController group. The DataSource goes into a DataSource group, and calling it MainDS. And the ViewDelegate? You guessed it right, it goes into a ViewDelegate group with the name MainVD. So for the program logic, I put MainLogic into a Logic group. All data models goes into a DataModel group. So, with an easy glance, I know where each file is depending on what I want to edit. Not a lot of searching for where I put something, everything goes into its respective group. The only stuff going into MainVC.swift file, are vars, outlets and actions.

This is probably not the perfect way of arranging a project, but for me it works fine. I really hope you could give me some feedback on it, and pointers on how to enhance the design pattern.


Im really happy with all the feedback I got in very short time, and one tip was to organize all the files in one group for each ViewController. So in MainVC, MainDS, MainVD and so on goes into a Main group. This is a really good idea, and Im going to give it a try in ome of my ongoing projects. Keep the good ideas coming, I really appreciate it!

Starting another Swift blog

The best way to learn is to teach, my old math professor told me. And he’s right. That’s the main reason for me to start blogging.

Im Geert-Jan Nilsen, 40, married, two kids, and programming Swift. I started coding assembly way back with an Amiga 500, and later switched to Mac, and found HyperCard. I made a patient journaling system for a local hospital in it, and later migrated it to SuperCard because the support of color and AppleEvents. Then the app evolved from a simple HyperCard Stack to a Server/Client system using AppleEvents over AppleTalk. A couple of years later I bought Prototyper and Think! C wich became Symantec C++. Fast forward, from 2006 Cocoa and Objective-C was the blend, first for OSX, later iOS. And now Swift.

When HairForceOne presented Swift for the first time, my emotions went from extatic to almost depressive, because now all my investment in C was straight out of the window. But after just a couple of hours checking out the Playgrounds, I was completely sold. Swift has been the best ever happened to me. The new way of thinking gave me a completely new look on the platform, and brought inspiration.

I could never have gotten to where Im today without the two greatest concentration of Swift-geniouses, StackOverflow and #swift-lang@freenode. And because of all the help I got from them, I decided to give something back to the community, and OpenSourced an important part of my first commercial product made in Swift, a signature capturer for concent forms, delivery apps, and so on. You can find it here on GitHub.

Another inspiration for starting Yet Another Swift Blog, is @andrewcbancroft and his great blog. Be sure to visit it.