On May 23, 2008, at 5:30 PM, [EMAIL PROTECTED] wrote:

Message: 3
Date: Fri, 23 May 2008 16:55:13 -0400
From: Andy Lee <[EMAIL PROTECTED]>
Subject: Re: File's Owner
To: Cocoa-dev <cocoa-dev@lists.apple.com>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

On May 23, 2008, at 2:49 PM, Johnny Lundy wrote:
I decided to once again go verbatim through Cocoa Fundamentals. So
far it has been largely "uh-huh, yep", but the File's Owner, my
nemesis, comes up again.

I tried to answer your File's Owner and NSApp questions last week
(copied below).  If you can indicate at what point in my explanations
you start getting lost, I can try to explain better.

Again, I'm sensing a very fundamental disconnect, perhaps more
fundamental than you realize.  Anybody can recite documentation, so
there's no need to tell us that and no need to recite the
documentation. I think it would be more helpful to tell us at what
*part* of the documentation you start to get lost, and what
specifically is confusing about it, perhaps as relates to your other
programming experience.

The point at which after it says "the proxy is filled in at runtime with the object that was set as the owner, ****so that the nib objects can communicate with other objects outside the nib*****.

What other objects outside the nib? I have nothing connected to File's Owner except the delegate, and looking at File's Owner's "off the shelf" connections, the only one it has is to the About.... menu item. So I don't see why any "object outside the nib" could use File's Owner to find out about "objects inside the nib", since File's Owner isn't connected to any objects inside the nib (except the About... menu item).

So I understand it's a proxy, I understand it has an object it knows as its owner, I know the standard owner is an instance of NSApplication aka NSApp global variable, but what I do not get is why I need this thing, or how it is needed to "connect the rest of the nib objects with an object outside the nib." What object outside the nib?



If the answer is that you draw a complete
blank, then we shouldn't be addressing that issue at all; you need to
step back to a more fundamental level and see if you feel fluent at
that level.

I draw a blank at understanding what it does. I come from a systems programming, BS and MS in CS, from Brown, and all-procedural background - assembler in 360, assembler in Meta-4 minicomputers doing 3-D graphics, taught by Andries van Dam if that means anything, the usual litany of procedural languages - Fortran, Basic, PL/I, PL/C, our own compiler design close to PL/I but faster, C, (no C++ or Java), complete graphics system in assembler like QuickDraw was, visited PARC and saw SmallTalk, Snobol, Cobol, MPW/MacApp, 4D databases, 6502 assembler for processing real-time NMI interrupts for data acquisition on the Apple II, Pascal on the early Macs, then since the introduction of OS X, several Carbon apps programming the device manager, several Cocoa apps, one ported to that platform Apple has that we can't talk about, numerous AppleScript Studio apps, which used AppKit extensively, tableViews and data sources for them, buttons, target/ action and outlets, and attended WWDC four times as well as maintaining a Select ADC membership for at least 6 years now and reviewing all the WWDC videos on Tiger and Leopard recently.

Whew. That was all for either school or hobby - only worked one summer as a real-time systems programmer for Foxboro Corp in Massachusetts before leaving for med school.

But I don't understand File's Owner. Everything else that I listed up there, I understood.



--Andy


Here's my reply from last week:

On May 15, 2008, at 11:11 AM, Andy Lee wrote:

On May 14, 2008, at 10:33 PM, Johnny Lundy wrote:
So it's the application instance. I don't understand what the
application instance is. I can recite the documentation, which says
it is a shared instance of NSApplication, also known as NSApp which
is a global variable, none of which help me.

To me this indicates a very fundamental disconnect, because what you
recited explains NSApp perfectly.  I can't tell where the disconnect
is, so I'll try to spell this out quickly.  No offense intended here
-- I honestly don't know where the disconnect is.

You are writing a Cocoa application.  There is a class called
NSApplication that represents the concept of a Cocoa application.
That's the purpose of a class in an object-oriented language, to
describe a *class* of things conceptually.  Classes are usually
named for the thing they describe -- hence "NSApplication".
NSApplication handles the generic things that Cocoa applications do:
managing the main menu, managing the window list, dealing with mouse
and keyboard events, and so on.

Cocoa applications create objects (instances of classes).  That's
what they do all day.  Objects get created, they send messages to
each other, they get dealloc'ed.  Thousands and thousands of
objects, all day long.  In your application there is one special
object that is an instance of NSApplication.  It represents the
application itself.  I repeat: there is an object in your
application that represents the running application itself.  There
is only one such object, and it is stored in a global variable
called NSApp.  That is what "application instance" means.

Why would someone bind to File's Owner? What specifically is it?

Unlike most other objects in a nib file (First Responder being the
exception), File's Owner is not a specific object.  It is a
placeholder for an "owner" object that will be specified when the
nib file is loaded.  You edit a nib file knowing that it will be
loaded at some point in your program, and *at that future time* the
owner of the file (hence "File's Owner") will be specified.

The file's owner gives your program access to the objects in the nib
file, through the connections you made to it in the nib.


Here's my problem. I didn't make any connections to File's Owner. I never have. Before bindings, I had a view object send an action to my class, by coding (IBAction) myMethod: in my code, and setting that action in the view object's action method.

With bindings, I bind the view object to the NSArrayController, and the controller to an NSObject whose class is set to my custom class. Nothing done with File's Owner at all.


I think newcomers sometimes assume that when you load a nib you get
some sort of NibObject that you can query to get at the objects in
the nib, perhaps using the name you assigned in the nib file.  This
is an understandable assumption, but you don't get any such object.
You need to specify a file's owner for the nib (using the second
argument to +loadNibNamed:owner:), and you need to have constructed
the nib so it connects the file's owner to at least one of its
objects.

--Andy



I understand that if I wanted to make another nib (which I definitely will need at some point), that I invoke loadNIbNamed:owner:, but I still wouldn't know why I was specifying an owner. I assume said owner would be an object, which might be one of my class instances, but really I have no idea.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to