R – How are objects defined in an XIB file and how are they created at runtime

bundlecocoainterface-builder

I've just purchased a Mac and am beginning to explore software development using Cocoa and Objective-C using XCode in Snow Leaped having come from a strong Microsoft and C# backgrund

All of the documentation and tutorials I have read use Interface Builder and XCode to create applications with user interfaces. My current understanding is that objects created by Interface Builder are in some way defined in an .xib file and created at runtime.

A bundle contains code and resources that accompany it. Is it right to say that an .xib file is in fact a bundle that contains UI resources and that this bundle is loaded (is that the correct verb?) at runtime and object instances are created?

If the abive is true is there any way I can see the code generated by Interface Builder and the point in code where these objects are created, without seeing this at least once I feel like there is a lot of "magic" happening and that isn't helping me at this stage of my learning.

Is there anything I should be reading to grasp the apparent paradigm-shift between C# / WinForms and Objective-C / Mac OS / Cocoa?

Best Answer

Is it right to say that an .xib file is in fact a bundle that contains UI resources and that this bundle is loaded (is that the correct verb?) at runtime and object instances are created?

No. A bundle is one of several specific directory structures, and a xib file is a regular file, not a directory.

A xib file contains descriptions of objects. When you compile the nib (usually as part of building your app), the nib compiler reads in the xib, creates the objects as described therein, and archives them into a nib, which isn't a bundle either.

When you load the nib in your application, the nib loader unarchives the objects and ensures all outlets are connected as they were in IB between its objects and to and from the File's Owner.

Don't worry about implementation details. Nibs Just Work. All you have to do is:

  1. Create xib files. If you use version control, these are what you tell it to track.
  2. Make sure they're in .lproj folders (so that localizers can create localized versions of them).
  3. Let Xcode handle the rest.