iCoder4777
iCoder4777

Reputation: 1692

Creating Views programmatically VS. nib

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 ?

Upvotes: 4

Views: 2234

Answers (4)

Rakesh
Rakesh

Reputation: 3399

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.

Upvotes: 2

Phineas Lue
Phineas Lue

Reputation: 317

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.)

Upvotes: 2

Rui Peres
Rui Peres

Reputation: 25907

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.

Upvotes: 4

Avi Tsadok
Avi Tsadok

Reputation: 1843

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.

Upvotes: 6

Related Questions