Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > What's *really* in a Nib?

What's *really* in a Nib?
Thread Tools
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Oct 21, 2003, 01:41 PM
 
I think I have a general understanding of "freeze-drying" and "reconstituting" instances of a class: You've got some data and some instructions on how that data is to be loaded into memory at runtime. That much seems to make sense to me...

But, what's really in a nib?
Classes?
Subclasses of Cocoa classes (NSFoo)?
Instances of classes?
Instances of subclasses?

Using IB, when you drag a button over into the window, is there some sort of subclassing going on?

Still using IB, when you use the nib window --> Classes tab to "create" a class, are you simply letting IB know about a class you plan on creating in your app, or is there something more going on?
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Oct 21, 2003, 05:07 PM
 
Have a look in the NIB contents (a NIB file isn't really a file, but a bundle, in the same way that a .app is usually a bundle). The files contained within (also having .nib extentsions) are actually text files and you can drag them onto TextEdit to view their content.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 21, 2003, 05:29 PM
 
Why don't you see for yourself? A nib is one of three things: a bundle containing other nibs, a plist, or an NSArchiver-style data stream. You can look inside and see how it's organized.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
johnMG  (op)
Registered User
Join Date: Oct 2003
Status: Offline
Reply With Quote
Oct 21, 2003, 09:53 PM
 
Chuck wrote:
>Why don't you see for yourself?

Ok. Looking into this NIB more closely (in a project mostly copied from the Hillegass
book but with a couple extra widgets thrown in), I see that the NIB bundle shows up as
a file in Finder (just like a .app would), but as a directory in Terminal.

Inside it are three .nib files:

Code:
[john ~/dev/osx/RandomApp/English.lproj/MainMenu.nib]$ ls -l total 32 -rw-r--r-- 1 john staff 334 Oct 15 16:11 classes.nib -rw-r--r-- 1 john staff 595 Oct 15 16:11 info.nib -rw-r--r-- 1 john staff 6288 Oct 15 16:11 objects.nib [john ~/dev/osx/RandomApp/English.lproj/MainMenu.nib]$ file * classes.nib: ASCII text info.nib: ASCII text objects.nib: data
classes.nib only contains

Code:
{ IBClasses = ( {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, { ACTIONS = {generate = id; seed = id; }; CLASS = Foo; LANGUAGE = ObjC; OUTLETS = {textField = id; }; SUPERCLASS = NSObject; } ); IBVersion = 1; }
and it seems that it has to do with the Obj-C class (Foo) I created to handle what
happens when you click the buttons. This seems to be simply a roadsign that
says my program will have this object in it at runtime.

info.nib contains

Code:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>IBDocumentLocation</key> <string>1157 32 520 332 1024 0 1024 768 </string> <key>IBEditorPositions</key> <dict> <key>29</key> <string>1143 405 318 44 1024 0 1024 768 </string> </dict> <key>IBFramework Version</key> <string>291.0</string> <key>IBOpenObjects</key> <array> <integer>21</integer> <integer>29</integer> </array> <key>IBSystem Version</key> <string>6R73</string> </dict> </plist>
Hmm... I can't make heads or tails out of that.

Finally, objects.nib (the biggest of the three) is binary... file doesn't
know anything about it. GetFileInfo doesn't tell me anything interesting.
... Egads! What's this? /usr/bin/nibtool!

Hmm... it seems to want you to run in on the MainMenu.nib directory rather than on
one of the individual .nib files. Running nibtool -a MainMenu.nib
yeilds a lot of information, some of which:

Code:
"Object 197" = { Class = "NSButton"; Name = "NSButton"; alignment = "2"; alternateImageName = "<null>"; alternateTitle = ""; autoresizingMask = "0"; bezelStyle = "1"; bordered = "1"; continuous = "0"; controlSize = "0"; enabled = "1"; font = "{name = System Font; pointSize = 13}"; frameRect = "{{109, 128}, {241, 32}}"; groupedIBObjectID = "<null>"; iBButtonBehavior = "2"; iBButtonType = "1"; imageName = "<null>"; imagePosition = "0"; inset = "2"; isLockedIBObject = "0"; keyEquivalent = ""; keyEquivalentModifierMask = "0"; soundName = "<null>"; state = "0"; tag = "0"; title = "seed random number generator"; transparent = "0"; };
suggests that there is no subclassing going on, rather, just setting a bunch of
member variables for the GUI objects present (in the above case, the "seed" button).

So, it looks to me like IB doesn't subclass anything; I think it just creates
instances of NS* GUI objects as you drag them to your Window/Menu and then sets
up their instance variable values for you according to your preferences (ie.
the text you put into buttons, how large you made things,..). Well, and then
archives those instances for you upon saving the .nib.

As for when you "create" a class in IB (like Foo above), nibtool didn't tell
me anything to suggest that there's anything more going on than simply maybe
creating some sort of stub of Foo (and its methods) so it can keep track of
where the GUI objects are supposed to connect to.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2