XCode: Using Storyboards and Xibs Versus Creating Views Programmatically

In this article, I wanted to document what I discovered in my search for an answer to the question: Is it an iOS best practice to avoid using Storyboards/XIBs and instead, create your views programmatically ? As a disclaimer, I personally tend to avoid using storyboards and XIBs simply because I feel that I’m more… View Article
Written by

Chris C

Updated on

Sep 05 2019

Table of contents

    In this article, I wanted to document what I discovered in my search for an answer to the question:

    Is it an iOS best practice to avoid using Storyboards/XIBs and instead, create your views programmatically ?

    As a disclaimer, I personally tend to avoid using storyboards and XIBs simply because I feel that I’m more in control when I create all of the views programmatically. I also ask all of the iOS developers whom I interview and more often than not, they’re of the same thought. We recently had a new member to our iOS team who advocated the use of storyboards and XIBs so it made me revisit this question.

    As with any debate, there’s always more than one side to the story. I set out with an open mind, put aside my own opinions and started searching for the facts of both using XIBs versus purely creating your views programmatically.

    Using XIBs

    Advantages:
    -You can quickly put together a UI
    -Straight-forward implementation for small apps with a minimal number of screens
    -You can have separate XIBs for different localizations (ie. languages or countries)
    -Great at laying out elements and visually spotting misalignments. It’s easy to make a slight adjustment to the layout

    Disadvantages:
    -It’s difficult to merge conflicts when working in a team environment (hard to diff, merge and read)
    -Highly dynamic views are impossible to describe as a XIB
    -Performance wise, it’s slower than creating views through code because the XIB needs to be read from the disk and analysed/parsed
    -XIBs lack customizations that you can do in code such as Quartz stuff (drop shadows, round corners)
    -Harder to debug (ie. if you forget to make a connection in Interface Builder or make a wrong connection)

    Storyboards

    Advantages:
    -Storyboards are nice for apps with a small to medium amount of screens and the requirements for navigation is relatively straightforward between views
    -You can mock up the flow of an application without writing much, if any, code

    Disadvantages:
    -Storyboards are not compatible with pre-iOS 5 so it makes supporting iOS 4.3 impossible
    -It’s hard to work in parallel in a team environment because everyone’s modifying the same file
    -Along the same lines, merging conflicted storyboards in GIT will be a pain
    -People have experienced bugs in XCode with the usage of storyboards (eg. having to frequently flush the DerivedData folder because of inconsistencies)

    Creating Views Programmatically

    Advantages:
    -It’s easier to merge conflicts and diff lines of code than it is a XIB file
    -You can trace through code when debugging and not have to look at Interface Builder
    -Performance wise, it’s faster view creation than XIBs
    -Creating views through code, gives you more control and free reign

    Disadvantages:
    -It’s harder to visualize the UI and grasp a mental picture of what it will look like if all your UI creation doesn’t happen in one place in your code
    -You can’t visually position elements, making it more time consuming to layout your views
    -For a newcomer to your project team, it will take them longer to grasp the app flow and navigation

    For you readers, what is your own experience? Share your thoughts and comments below and I’ll update this post!

    Shameless plug to my video channel. I’ll be adding new stuff soon!

    Further reading:
    Interface Builder (XIB) or Code when merging in a team
    environment?

    Should or should not use nib files ?
    When to use Storyboard and when to use XIBs



    Get started for free

    Join over 2,000+ students actively learning with CodeWithChris
    44 Shares
    Share
    Tweet
    Pin
    Share
    Buffer