To understand this difference, it is important to have basic comprehension of the 2 frameworks used in iOS development:
- 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.
- 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 and XIB
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.
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
Mobile App Development Best Practices – 04.10
iOS New and Deprecated APIs in iOS 17 Abstract Class vs. Protocol-Oriented Approach in Swift Comparing the Performance of the...
New and Deprecated APIs in iOS 17
In this video, I would like to share with you some things that were either deprecated or added in iOS...
Promova helps people with dyslexia learn languages
The new Promova feature comes just in time for National Dyslexia Awareness Month and is available on the platform for...
Notify – A simple note application with modern MVVM, Compose and Material3
Notify is a simple note application that is built with Modern Android development tools. This project showcases the Good implementation...
Mobile App Development Best Practices – 03.10
iOS MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming How to build a Tuist plugin and publish it using...
How to make and use BOM (Bill of Materials) dependencies in Android projects
By using a BOM dependency, you can avoid specifying the versions of each individual library in your app, and let...