In Chapter 4, I talked about ways of obtaining an instance. You can directly instantiate an object type:
let v = UIView()
Or you can obtain a reference to an already existing instance:
let v = self.view.subviews
But there is a third way: you can load a nib. A nib is a file, in a special format, consisting of instructions for creating and configuring instances. To load a nib means, in effect, to tell that nib to follow those instructions: it does create and configure those instances.
My example of a UIView instance is apt, because a UIView is just the kind of instance a nib is likely to create. Nibs are edited in Xcode using a graphical interface, much like a drawing program. The idea is that you design some interface objects — mostly instances of UIView and UIView subclasses — that you want to use in your app when it runs. When your app does run, and when the moment comes where you actually need those interface objects (typically because you’re about to display them in your visible interface), you load the nib, the nib-loading process creates and configures the instances, and you receive the instances and insert them into your app’s actual interface.
In fact, because you’ll mostly be using view controllers — subclasses of UIViewController — you won’t even have to do that! View controllers already know how to work hand in hand with nibs: each of your app’s view controllers will load its own view nib and retrieve the resulting instances and put them ...