How does MainMenu.xib get loaded in a Cocoa application?

  • I'm new to Cocoa and am trying to understand File Owner's and Nibs.
    When I create a simple Cocoa application and build and run it, a window --
    specified in MainMenu.xib -- opens. How exactly does this window open? Is
    there any code for this anywhere? I wasn't able to find any.

    (I tried setting a breakpoint in main() but to no avail)
  • On Dec 4, 2008, at 10:03 PM, Debajit Adhikary wrote:

    > I'm new to Cocoa and am trying to understand File Owner's and Nibs.
    > When I create a simple Cocoa application and build and run it, a
    > window --
    > specified in MainMenu.xib -- opens. How exactly does this window
    > open? Is
    > there any code for this anywhere? I wasn't able to find any.

    In NSApplicationMain(), which is called from your main(), there's code
    that loads the "Main Nib File" as specified in your target's
    properties, and makes the shared NSApplication instance that nib's
    owner.

    Why do you ask? Normally, it's not something you'd really need to
    worry about.

    sherm--
  • There's a setting (I can't relocate it) that declares a "Main" NIB,
    etc.  'Tis a property of one of the main files (like the project or
    target).  Look around, you should be able to find it with a bit of
    effort.

    Quoting Debajit Adhikary <debajit...>:

    > I'm new to Cocoa and am trying to understand File Owner's and Nibs.
    > When I create a simple Cocoa application and build and run it, a window --
    > specified in MainMenu.xib -- opens. How exactly does this window open? Is
    > there any code for this anywhere? I wasn't able to find any.
    >
    > (I tried setting a breakpoint in main() but to no avail)
    >
  • On Dec 4, 2008, at 8:03 PM, Debajit Adhikary wrote:

    > I'm new to Cocoa and am trying to understand File Owner's and Nibs.
    > When I create a simple Cocoa application and build and run it, a
    > window --
    > specified in MainMenu.xib -- opens. How exactly does this window open?

    It uses the value of the key "NSMainNibFile" in your application's
    Info.plist.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • On Dec 5, 2008, at 2:08 PM, Sherm Pendley wrote:
    > On Dec 4, 2008, at 10:03 PM, Debajit Adhikary wrote:
    >
    >> I'm new to Cocoa and am trying to understand File Owner's and Nibs.
    >> When I create a simple Cocoa application and build and run it, a
    >> window --
    >> specified in MainMenu.xib -- opens. How exactly does this window
    >> open? Is
    >> there any code for this anywhere? I wasn't able to find any.
    >
    > In NSApplicationMain(), which is called from your main(), there's
    > code that loads the "Main Nib File" as specified in your target's
    > properties, and makes the shared NSApplication instance that nib's
    > owner.

    Sherm answered how the nib gets loaded, but you also need to know what
    it means for a nib to load.

    A nib file contains archived objects.  When the nib is loaded, the
    objects are unarchived, i.e., new objects are instantiated with all
    the attributes and interconnections that were specified in the nib.

    Windows are objects.  The window that appears when the nib is loaded
    is one of the objects that was archived in the nib.  So you won't see
    a specific line of code that says "create this window."  Nib files do
    not cause code generation.  The window instantiation is implicit in
    the unarchiving that is performed when the nib is loaded.

    See also:

    "Cocoa Fundamentals Guide: Nib Files and Other Application Resources"
    <http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals
    /CoreAppArchitecture/chapter_7_section_8.html
    >

    --Andy