Instances of the UINib class serve as object wrappers, or containers, for Interface Builder nib files.


A UINib object caches the contents of a nib file in memory, ready for unarchiving and instantiation. When your application needs to instantiate the contents of the nib file it can do so without having to load the data from the nib file first, improving performance. The UINib object can automatically release this cached nib data to free up memory for your application under low-memory conditions, reloading that data the next time your application instantiates the nib. Your application should use UINib objects whenever it needs to repeatedly instantiate the same nib data. For example, if your table view uses a nib file to instantiate table view cells, caching the nib in a UINib object can provide a significant performance improvement.

When you create a UINib object using the contents of a nib file, the object loads the object graph in the referenced nib file, but it does not yet unarchive it. To unarchive all of the nib data and thus truly instantiate the nib your application calls the instantiate​With​Owner:​options:​ method on the UINib object. The steps that the UINib object follows to instantiate the nib’s object graph are described in detail in Resource Programming Guide.


Creating a Nib Object

init(nib​Name:​ String, bundle:​ Bundle?)

Returns a UINib object initialized to the nib file in the specified bundle.

init(data:​ Data, bundle:​ Bundle?)

Creates a UINib object from nib data stored in memory.

Instantiating a Nib

func instantiate(with​Owner:​ Any?, options:​ [Any​Hashable :​ Any]? = nil)

Unarchives and instantiates the in-memory contents of the receiver’s nib file, creating a distinct object tree and set of top level objects.


Inherits From