Pros and cons of using XIB and programmatic views

I want to decide whether it is better to use XIB or to completely construct my views using code.

Until now, I read that when you develop your views on the interface designer, they are pre-built, so even if they use more memory, the user feels that everything is faster.

People say that doing everything using the code is harder, but I find it just as easy, so I want to know if someone really experienced some real speed increase when using knives.

What were your experiences, tips, etc.

Thanks!

+4
source share
5 answers

You should be able to do both - there are times when creating software is better / easier and times when using .xib is better / easier. Even if you only ever do something in one direction, you will come across code that makes it different, and you will need to deal with it.

If you do not know how to use IB, then creating your representations in code will of course be easier. That is why you must learn to use IB. Once you realize that this is possible, most likely you will need to build most of the user interface based on the view your application is likely to need. IB helps you rebuild objects, center objects, align baselines, associate controls with their goals and actions, etc. I believe that it is safe to say that everyone who uses IB effectively experiences a "real increase in speed when using knives."

+3
source

You must know how to use both. The differences in performance between them are small and should not be the reason that you choose one or the other.

Many people who are not familiar with iOS development have a misconception that nibs (.xib files) are inferior to creating your user interface programmatically, and if you use IB, you are not a good iOS developer. This opinion is 100% incorrect. IB was created by Apple and is used by Apple developers to create their own applications for Mac OS X and iOS. If IB (as a tool) is good enough to be used by some of the best developers in the world, it is probably good enough for most of us.

In practice, I have found that a combination of the two is usually suitable for counting.

In my own applications, I find that .xibs are great for quickly defining the fundamentals of your views, and they allow you to iterate very quickly, giving you a preview of how your look will look. It is also much easier to use automatic linking in a .xib file.

Then, when you need to do more advanced things, such as adding fancy animations or moving views around for what IBOutlets are for. Everything you put in the tip can be found through IBOutlet. This allows you to programmatically make your look livelier.

Finally, you must fully understand what automatic use (.xib) does for you. You must understand what happens when .xib objects are thawed. There are many resources on the Internet to better understand .xib files.

Also, learn how to use .xibs in an encapsulated way. For example, .xibs are crazy, useful for things like prototype cells, and they allow you to preserve the modular structure of the code (much more than storyboards). In addition, your view controllers will require less user interface code.

Finally, I always say that people should think of IB / .xibs as jQuery. This is going to save you a lot of time, but the best developers still know how to do everything in javascript if they should.

Good luck and have fun!

TL DR version

  • Performance is not taken into account when deciding whether to use xxs or not.
  • Use .xibs because they give you a preview of the view you are creating and allow you to iterate quickly
  • In practice, most applications will use a combination of both. You add animation programmatically or move views around, but .xibs will be the starting point.
  • Fully understand what happens when objects in .xib are unfrozen.
  • You will be more productive, but be sure to fully understand what is happening behind the scenes.
+2
source

I would always use XIB files if there were no reason. This makes it easy to keep your views in the future.

Some reasons for creating views programmatically can be:

  • The control must be modified, modified, or modified depending on something else
  • Management needs to be added or removed dynamically

There may be more reasons, but not many.

If you programmatically create views when not necessary, you make it difficult for other developers to try to figure out what the view will look like and change it.

+1
source

If you create your views programmatically, you can control the loading of elements. for example, you can use lazy loading and load secondary buttons, subviews, etc. a second after more important elements, allowing key parts of the user interface to rise faster. You can even animate some elements in position.

If you use IB, you get recommendations on the correct distances between elements and positioning, but you can always copy the coordinates from IB to code if you don't change the design often.

For simple user interface elements, you will get more lines of code to support if you create them programmatically.

0
source

IB and NIB do a lot to optimize the loading / unloading of views, but they are largely focused on minimizing memory usage compared to the perceived speed for the user. For example, lazy loading if something can make the user interface of the application a little slower, but this should make the memory usage lower. This, in turn, can increase the efficiency of applications as a whole over a large application and is very enthusiastic, but difficult to define "performance" in the narrow sense. It is also difficult to say when you should or should not use IB - it will be several times when it will be much better for you to do this in code.

An often forgotten element for IB or not debate is development speed, especially if you have several developers. In a larger team / project, you will likely have some developer specializing in infrastructure, business logic, etc. Applications and some developers (developers) who are more specialized in the user interface. In this case, the use of IB will facilitate their work independently, which should make the overall development more effective.

I see IB as the main part of the development platform for iOS development. This is not the right decision in any situation, but not knowing how to use IB will be a real limiting factor.

0
source

All Articles