Skip to content

Instantly share code, notes, and snippets.

@iraycd
Last active January 26, 2022 07:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iraycd/1256ca55f7cf73ce3940 to your computer and use it in GitHub Desktop.
Save iraycd/1256ca55f7cf73ce3940 to your computer and use it in GitHub Desktop.
Storyboard Vs XIB

It is not to tell which one is the best. because which one is good to tell based on team requirement.

if your team have single developer its good for storyboard working less consumption time.either more number of developers use xib because it is not easily to merging the module/tasks

xcode-using-storyboards-and-xibs-versus-creating-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)

##Notes Professional developer MUST use xibs, but a hobbyist, new to programming, developer might be helped if he uses storyboard.

Storyboard disadvantages:

  1. It REALLY gets VERY VERY slow to build even for a very very very little think ( every single view in it must be rebuild ). Also it is very hard to edit even with an iMac with 8 or 16 gb ram if the Storyboard gets bigger. It's even hard to open it.
  2. No reusability. There is no way you can import immediately a View/ViewController with its view to another project. It will be connected with other ViewControllers, Views Or Segues and that will make it like a big "don't touch" think.
  3. There is so much lag when the project gets bigger even for the smallest layout constraint to be added or edited, that you never want to touch it.
  4. If you use the cells by automatic cell addition of storyboard, you cannot use the same cell build in two points.

Advantage:

  1. Automatic Cells (But this is also a disadvantage because a cell cannot be reused as is to another view)
  2. Segues etc would make it easy for someone to understand with a single point of view what is happening.

Xibs:

  1. Fully portable.
  2. Open/Edit/Build SO MUCH MUCH MUCH faster than a storyboard that gets bigger

conclusion: If you are a hobbyist developer who will make an app for his business for fun, you should use storyboard because it will it easier to understand things. BUT, if you a professional developer, you MUST use xibs for VCs, Cells, etc, Because this is the only way to make them really reusable and portable, in order to gain so much time for the next project, or even when having to make a little change or build the storyboard again.

Explanation why xibs are more "reusable and portable" for me: Things in programming must be kept in different models, files, entities, modules. One must be as least dependent on another thing as it can get

##When to use Storyboard and when to use XIBs?

I have used XIBs extensively and completed two projects using Storyboards. My learnings are:

  • Storyboards are nice for apps with a small to medium number of screens and relatively straightforward navigation between views.
  • If you have lots of views and lots of cross-navigation between them the Storyboard view gets confusing and too much work to keep clean.
  • For a large project with multiple developers I would not use Storyboards because you have a single file for your UI and cannot easily work in parallel.
  • It might be worth for large apps to split up into multiple storyboard files but I have not tried that. This answer shows how to do segues between storyboards.
  • You still need XIBs: In both of my Storyboard projects I had to use XIBs for custom table cells.

I think Storyboards are a step in the right direction for UI implementation and hope Apple will extend them in future iOS versions. They need to resolve the "single file" issue though, otherwise they won't be attractive for larger projects.

If I start a small size app and can afford iOS5 only compatibility, I would use Storyboards. For all other cases I stick to XIBs.

@vahids
Copy link

vahids commented Aug 25, 2018

Seems like this article is very old.
A lot of Storyboard issues fixed now.

@saish98
Copy link

saish98 commented Oct 14, 2020

But still, if your project is big then go for XIB. Storyboard compile time is more as compare to xib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment