Which is more efficient way? StoryBoard or XIB?

31,982

Solution 1

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

If you are a single developer, it is good to use storyboard because it consumes less time. If the team consists of many developers, use xib, otherwise, it is not easy to merge the modules/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 (i.e. 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)

Solution 2

My point of view that a professional developer MUST use xibs, but a hobbyist, new to programming, developer might be helped if he uses storyboard.

Storyboard

After a 3 year project work with a single storyboard I can tell a lot of 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

Solution 3

Comparing XIB and storyBoard, StoryBoard is fast.

But Actually fast when do the whole project in programatically.

in storyboard when we compile all storyBoard is Archive to file. and unArchive then run the application. But, in programatically Classes are allocated at the run time only.

Recommended do project using storyboard.

Share:
31,982
Vishal Sharma
Author by

Vishal Sharma

I am passionate software engineer with around 6+ years of experience in software industry. I have pretty good experience on app development in below list of technologies : Native iOS React native. Phone gap If you have any query then you can reach me on [email protected].

Updated on November 25, 2020

Comments

  • Vishal Sharma
    Vishal Sharma over 3 years

    My question is slightly different then my title suggest. I have worked with xib. Now i am trying to work with storyboard. My question is if we are navigate through one class from another class, is StoryBoard giving benefit for better memory management. Suppose we have 2 ViewControllers: ViewControllerA and ViewControllerB. We are trying to go through ViewControllerA --> ViewControllerB. Now, in Xib our approach is below;

    ViewControllerB *VCB = [ [ViewControllerB alloc] init];
    [self.navigationController pushViewController: VCB Animated: YES];
    

    Where in Story Board,

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"Second"])
        {
            SecondViewController *objSecond = (SecondViewController*)[segue destinationViewController];
    
        }
    }
    

    And Do,

    [self performSegueWithIdentifier:@"Second" sender:self];
    

    So, My question is We alloc our class in Xib, Where in storyBoard we aren't. So is there any memory allocation advantages in storyboard?

  • Tiago Lira
    Tiago Lira almost 8 years
    This answer assumes one storyboard for the WHOLE project. You can easily divide it into one storyboard for each 1-4 view controllers (related ones, or part of a module), and you get al the new features without the speed and collaboration issues.
  • Giorgos Ath
    Giorgos Ath almost 8 years
    But if you split into a lot, seems more like a XIB-wise solution. don't you think? And except that, you don't have a lot of XIB-Advantages. I think you should reconsider that, specially when you started thinking that diving is better ;) ... Thanks.
  • Kiran Ruth R
    Kiran Ruth R about 7 years
    Can you link a source where apple recommends using storyboard and why ? TIA
  • Kiran Ruth R
    Kiran Ruth R about 7 years
    Can you link a source where apple recommends using storyboard and why ? TIA
  • Zonily Jame
    Zonily Jame almost 7 years
    @GiorgosAth, using Multiple storyboards is better than 1 xib per UIViewControllers, I've worked in a project where there are atleast 40 UIViewControllers, and do I tell you, building (archiving etc) 10 storyboards is a lot faster than building 40 xibs. Think of it like this for 1 feature you create one storyboard, example: Login, Registration, Transaction, Settings, etc. btw: I use both xibs, storyboards, and coded UIViewControllers for my projects.
  • user3344977
    user3344977 almost 7 years
    @KiranRuthR "For iOS developers, using storyboards is the recommended way to design user interfaces.": developer.apple.com/library/content/documentation/General/…
  • shim
    shim almost 7 years
    That doesn't say anything about memory management though. This says something similar but says "because they enable you to visualize the appearance and flow of your user interface on one canvas". If that's the only reason, it's not good enough because of all the disadvantages it introduces.
  • Jeff
    Jeff over 6 years
    If your concerned with speed. Use multiple storyboards with one viewController in each.
  • Vyachaslav Gerchicov
    Vyachaslav Gerchicov over 5 years
    Downvoted! 1)storyboards are hard to merge and it depends on how much views storyboard contains; 2)storyboards even with few controllers have worse performance than xibs - you change the color of one element and may wait for considerable while it is updating. 3)Is it harder to debug one view or a lot of views (storyboard) and a lot of linked code files? 4) you can mock up the app flow... but if it is linear only and won't have serious changes in future which is a very rare case
  • Lothar
    Lothar almost 3 years
    Can someone comment on it about the situation in 2021 ? How is the splitting Storyboards into multiple solving all the mentioned problems? On MacOS i can't see anything better than using XIBs. But now i have to do iOS
  • Jan Z.
    Jan Z. over 2 years
    I recently started working at a software for MacOS that has been in development for ~ten years now, with currently 40-50 devs adding here and patching there in parallel. Even some XIBs in this project become slow in IB on average 2019 MacBook Pros with 16GB of RAM. So we have to split them up into several smaller parts, stitching them together at runtime. From my point of view I clearly see the advantage of modularity here XIBS offer.