Post

Interface Builder or Programmatic UI?

I want to look at this topic under two main headings:

The Development Phase

  • You can build the visual interface much faster. Because you can see the final output, the chance of making a mistake is low.
  • With the programmatic approach, since you cannot see the final state of the interface, you have to picture it in your head, and on moderately complex screens you may need to do some trial and error.

Code Review and Maintenance Phase

  • If more than one person is working on a storyboard at the same time, you can run into a lot of conflicts during code review.
  • Because Interface Builder code is hard to read, people may not be able to do a layout review. (But then again, most people don’t review programmatic layout code either. :))
  • Reading and understanding layout code written programmatically, imagining what kind of screen it will produce, and changing the code when needed takes more time.

Conclusion

What matters is to define a single “source of truth” for each purpose. For example, we can build the layout in IB and then change properties from code. We should not go down the path of changing some properties from IB and others from code. You cannot do everything from IB; for things like animations you already have to use code, so some layout code will leak into the codebase no matter what.

If you use storyboards, you need to watch the number of view controllers they contain. You should split flows into different storyboards using storyboard references. If you work with different teams, it is important to distribute the flows across those teams.

Programmatic code can be a bit better for performance as well, though the difference is negligible.

In the end, the most important criteria will be the size of the project, how separable the flows are from one another, the number of people who will work on it, the project’s budget, and most importantly which approach you feel more comfortable with over time.

This post is licensed under CC BY 4.0 by the author.