views:

2535

answers:

4

Back in the day of C/C++, the part of the language that really hung me up was pointers. I understand them now, of course.

Now, Interface Builder Proxy Objects or more importantly, how to use Interface Builder and what to put in the .XIB window (window that contains the File's Owner, First Responder, etc...) for a given XIB.

I've gone through quite a few examples from books and samples found both in Xcodes examples and around the web. They have been helpful, but I still feel a little lost.

I feel that understanding IB is very important to understanding how to write Mac/iPhone/iPod touch applications.

I have gone through the following resources so far: Aaron Hillegass' Cocoa Programming for Mac OS X Pragmatic Programmer resources: Becoming Productive in Xcode (screencast) Cocoa Programming Coding in Objective-C 2.0 (screncast) Writing Your First iPhone Application (screencast) iPhone SDK Development

I've also gone over the Interface Builder Users Guide PDF from Apple.

Any suggested tips/resources will be appreciated!

+1  A: 

With the exception of "File's Owner" (which gets hooked up when the nib/xib is loaded), the objects you create in IB are real objects, not proxy objects.

You may want to look through some existing example code to see how IB hooks things up. Is there anything in the documentation/tutorials you've read that confuses you? It's hard to do much with "a little lost".

Nicholas Riley
Everything I have read tells me that File's Owner, First Responder and Application are all proxy objects. The rest are called Top-Level objects. The window with the icons I was referring to is called the Nib document window.As I stated in my question, I have read through quite a few resources.I'm "a little" lost because I have been able to make some very simple single window applications. Nothing all that fancy.I start having issues when it comes to knowing how much to put in a single XIB. The user guides tell you what everything is, but not best practices.
VesperDEM
Also, apparently, posts here remove some formatting. I had the paragraph about what resources I had looked at separated by lines. Apparently, this site doesn't like Carriage Returns in posts. At least single CR's.
VesperDEM
Application's a bit different in that it always gets hooked up to the app object. First Responder is not exclusively an IB concept, it is delivering messages to the responder chain. (If you don't understand how that works, read about it.)Anyway, one window and one or more controller per XIB is usual. You're trading off the time to unpack the objects for memory usage. Again, poke around some real apps to develop your tastes.If you've got comments about the lack of support for formatting in comments (I agree with you), click on the "feedback always welcome" link at the bottom of the page.
Nicholas Riley
+19  A: 

First, placeholder is a better word than proxy here.

Normally when you have an object in a NIB/XIB file it means that loading the NIB file will create that instance. The placeholder objects are objects that will already exist when the NIB file is loaded, and they appear inside of the NIB so that you can make connections between the objects that will be created by loading the NIB and the objects that already exist.

The file's owner, first responder and application are all placeholders.

The file's owner is placeholder for the object that will load the nib. All of the NIB loading methods take an 'owner' parameter. When you make a connection with the File's owner, when it's established at runtime, it will be connected to the owner object passed in to the nib loading method. Many UIKit and AppKit classes invoke the nib loading methods for you. NSApplication, NSViewController, NSWindowController, UIApplication, and UIViewController all load NIB files on your behalf. When they do that they pass self as the owner parameter to the nib loading methods. That's why when you use a view controller or a window controller you set the file's owner to your subclass and make most of the connections between your views and the file's owner.

The NSApplication instance is a simple placeholder for [NSApplication sharedApplication]. That's a global singleton and the icon in Interface Builder represents that global singleton. Loading the NIB file does not create a second NSApplication instance. By contrast, when a NIB file contains a window, if you load it a dozen times, you'll have a dozen window instances, but still one NSApplication instance.

The first responder is unique. Connecting an action to the first responder means that when the action is fired, it should dynamically be sent to the responder chain. The responder chain typically starts with the focused view, and continues up through the view hierarchy and includes some controllers and delegates. Each object in the chain gets a shot at handling the action. Menu items work great with the responder chain. If you had a menu item for "Make Bold" that is supposed to make the currently selected text bold, you might start by hooking that up to an NSApplication subclass, but then you'd have to know all of the situations that "Make Bold" applies, and how to handle them. A text view and an editable web view would probably need different code to handle "make bold" and bottling this all up in one object would get quite complex and wouldn't be very extensible. Instead you could connect the "Make Bold" menu item's action up to a makeBold: action on the First Responder. This would mean that when the menu item was selected, the focused object, or one of it's parents that responded to makeBold:, would get the makeBold: message. Now many classes can implement a makeBold: method and respond to this menu item when they're in focus.

Jon Hess
Thank you VERY MUCH for that explaination. That should be in books and in Apple's documentation! Its exactly what I needed.I "get it" now.
VesperDEM
A: 

Apple has the following doc which explains the File's Owner, First Responder and Application placeholder objects found in Interface Builder NIB/XIB files here:

Interface Builder User Guide: Placeholder Objects

I realized in your question you mentioned reading Apple's Interface Builder docs, but I felt it's appropriate posting this here for future reference. Also, the docs have been updated since your question was first asked, so it's possible they made things more clear since then.

Dave Gallagher