views:

371

answers:

2

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?

+1  A: 

The key thing to realize is that there isn't any code in the normal sense...at least, nib/xib UI resources are not simply contruscts of objective-c code that are merely generated by the Inteface Builder. These are objects that are sort of "frozen" in the nibs and "unfrozen" when needed by the apps (or awakened, I guess, as the awakeFromNib would suggest). They are archived in xml/plist/etc form, rather than being a framework for generating objective-c source code.

Consider them objects that have been serialized as xml or other data.

phoebus
I sort of figured that who whole NIB/XIB thing was a container for objects and that there would therefore have to be some type of serialization going on, guess im not going to find anything analogious to a designer.cs file....oh well, more learning to do I guess
Crippledsmurf
+2  A: 

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.
Peter Hosey
Thanks, this was quite informitive and is somewhat different to the code-generation based stratergy used by Visual Studio's Forms designer. Interface Builder doesn't generate code in a NIB but a description of an object
Crippledsmurf