Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am curious to know if anyone has any experience comparing the load time performance of iPhone apps with views laid out in NIBs vs. views laid out entirely programmatically (here is a similar question).

Is there really any advantage of views laid out entirely programmatically over views laid out in NIB ?

share|improve this question
2  
Except for the performance, programmatically created views are easier to handle if you are working in teams and have to merge stuff via git. – Marc Mosby Apr 23 at 6:15

4 Answers

up vote 2 down vote accepted

There are some advantages by doing it on code:

  1. Better to work with several people. It's easier to resolve conflicts when committing to a repository.
  2. You rely on what you see on the code, and not in something hidden in the nib file (some pesky option you select without being aware). You have: what you see is what you get.

With nib:

  1. I would say it's faster to develop.
  2. The code it's not so "polluted" with every single detail about your interface.
  3. I also would stay it's easier for people who don't have a lot of experience.

About performance, you can actually check this.

share|improve this answer

According to Apple, XIB file loading time is longer than build UI programmatically. Saw that in a WWDC lecture.

If performance is what counts, build your UI in code and not in IB.

share|improve this answer
1  
it's better to give reference links. – Shivan Raptor Apr 23 at 6:22
If u have reference to that WWDC video,please share.. – iCoder4777 Apr 23 at 6:26
I don't remember which video is it exactly, but I can look for it. It's defiantly from the last WWDC (2012). – Avi Tsadok Apr 23 at 6:29

When I was beginning to learn iOS programming, I was building UI in xib file. But when I had developed some projects, I began to just write code to implement my UI.

There are some benefit through building UI programmatically:

First, by writing code, you have the view hierarchy clearly in you mind, and the view hierarchy can be important to efficiently implement your UI.

Second, if your UI is complicated, for example, with some animation or transform, you will benefit quite a lot from coding UI. Even sometimes you may not use UIView to build UI, you may use CALayer to accomplish some effect, which can not built by xib file.

Furthermore, when you get used to building UI programmatically, you will love it, because you can just code in the .m file and has no need to worry about the xib file.

However, if you are just a beginner in iOS programming, just fine to get start with xib file.

(Apple now provide StoryBoard, I have not learned about it, you may learn it to find if there is anything new.)

share|improve this answer
The view hierarchy is visible in the interface builder also. Although you can't do everything through code, ignoring IB out completely wouldn't be the right approach. Why would I want to build an entire view hierarchy through code when it can be easily done through IB. – Rakesh Apr 23 at 6:47
Actually, through code, we can implement everything built with IB. It is just about which approach is more efficient. I love IB when I was starting to learn iOS programming, IB is really easy to learn and use, but when I was developing more complicated UI, I think code can be more efficient. @Rakesh – Phineas Apr 23 at 7:05
Sure in code everything can be implemented that is done in IB. But only it takes more effort (no matter how fast you type. :) ). What I am trying to say is the most efficient approach won't be an only IB/only code approach. It would be a mix of both. I've tried to put my thought into an answer. @Phineas – Rakesh Apr 23 at 7:13

IMO a mix of both would be the right choice. Using interface builder for defining the basic layout (i.e a xib that doesn't change much over time) and default options of views and for the rest can be done programmatically (specific tweaks and effects). This should solve the source control and performance problems to some extend.

Although once we start off creating views programmatically ,we continue doing it for every time not realizing that the same thing could be done with much less effort in Interface Builder. After all if it's a GUI we are building it's better to have a visual reference.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.