The Magic Delegate

  • I'm looking at the Cocoa CoreData Application template in Xcode 3, and
    something has me a little puzzled.

    The only class in the template is <projectname>_AppDelegate. It's a
    bit of a stretch in naming because the only delegate method in it is
    applicationShouldTerminate:, but sure enough, its set as the
    NSApplication delegate when the App is run, and
    applicationShouldTerminate: does its stuff.

    Why question is how?

    There are no calls to setDelegate: in the project, and IB shows no
    connection to the delegate outlet of the application instance.

    So how is this class being set as the delegate for the NSApplication?
    Is there another method of doing this that I don't know about?
    Is it magic?

    Paul (Trying to get his head around some of the stuff behind the
    curtain)
  • Hello Paul,

    The app's delegate is the Principal Class which you can set by
    selecting the target, choosing File > Get Info and going to the
    properties tab. This setting will be reflected in your apps Info.plist.

    Johan
  • On 16 Nov 2007, at 14:15, Johan Kool wrote:
    > The app's delegate is the Principal Class which you can set by
    > selecting the target, choosing File > Get Info and going to the
    > properties tab. This setting will be reflected in your apps
    > Info.plist.

    Except in this case the Principle Class is set to NSApplication

    From Info.plist:

            <key>NSPrincipalClass</key>
            <string>NSApplication</string>
  • On 16 Nov 2007, at 14:43, Chris Campbell wrote:

    > On Nov 16, 2007, at 9:01 AM, Paul Sargent wrote:
    >
    >> There are no calls to setDelegate: in the project, and IB shows no
    >> connection to the delegate outlet of the application instance.
    >
    > Are you sure you're looking at the right nib file (MainMenu.nib)?
    >
    > I created a new "Core Data Aapplication" project and opened
    > MainMenu.nib, and I see that the delegate outlet of File's Owner
    > (indeed, NSApplication) is connected to the instance of
    > MyCoreDataApp_AppDelegate in the nib file:

    Thank you, I'm not crazy.

    I was looking at the Application instance, rather than the File's
    Owner. Hence I didn't see it, but it make perfect sense to me know.
    Both point to the same thing in this case.

    > Move along folks, there's no magic here. :)

    It's always a disappointment when you workout how the trick is done.
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today