Faster way to load Nib file from a bundle in iOS?

ios, nib, nsbundle, objective-c

Solution

It sounds like you're looking for the `UINib` class. From the documentation:

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.

Problem

I have an app which utilises a set of custom "controls" which are loaded on demand from Xib files using methods similar to the below: ``` NSArray * topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AudioPlayer" owner:self options:nil]; InteractiveMovieView *newAudio = [topLevelObjects objectAtIndex:0]; ``` This approach works great except where there are multiple controls loaded at once (in effect on one "page" of the app). Loading from the bundle each time is clearly inefficient but I can't find another way of approaching this. I've tried loading the nib into a `copy` property once and returning it on demand for re-use, but that doesn't work as the copy returned is never a "clean" copy of the blank nib. I hope that makes sense, and all help is appreciated.

Original source