Connect with us


Difference between Nib and Xib (iOS)

To understand this difference, it is important to have basic comprehension of the 2 frameworks used in iOS development:

  1. The first and the oldest is the UIKit, at the beginning of its life cycle it was built to be used with Objective-C language, but after some time it was adapted and updated to be used with Swift, a new and easier language to work with. For being the first framework, it is still the most used on iOS.
  2. The other one is SwiftUI, this framework was built to bring new development paradigms to iOS, for being a newer way of development it was chosen to use Swift as the main language, completely discarding objective-c from the framework.

The quick explanation between the difference of UIKit and SwiftUI was important because XIBs and NIBs are directly related to Objective-C, so these two concepts only exists in UIKit since SwiftUI does not use this language.

This article will be more theoretical, focused on showing the difference between the two topics, below is an article showing how to use XIB to create reusable components.


NIB stands for “NeXTSTEP Interface Builder” and XIBS stands for “Xcode Interface Builder”, analyzing the name is noticeable that both are related to building interfaces. They can create interface components where these items are constructed in a way that generally makes them reusable, which means you can use these components on other screens without having to rebuild this item from scratch.

The XIB is where the components are built, being possible to use in its construction the components that are children of a UIView, so it is possible to add any primitive iOS component, for example: UIScrollView, UITextfield and also any other XIB that you built that is a child of UIView. Furthermore, it’s possible to change the look of these components by changing their height, width, color, and positioning on the screen.

The NIB is the initialized UIView, with this object already loaded it is possible to change by code the data shown by the component and change its structure, adding and removing components, changing their color, changing the positioning of the internal items, etc.


In figure 1 we have a card built using XIB, it is a UIView that will be reused later, to show a set of cards.

Example of a card made in XIB

Inward the code below, between lines 7 and 10 we have the init called when initializing the view programmatically and between lines 12 and 15 we have the init called when it is initialized through the visual method. In both constructors, we call the standartIntit method on line 17, where the configuration is so that swift knows how to initialize the XIB as NIB.

Full Article: Francisco Samuel da Silva Martins @ Medium