Object creation order in Interface Builder

Discussion in 'Mac Programming' started by psantacr, Aug 8, 2008.

  1. psantacr macrumors newbie

    Feb 16, 2008
    Hi all,

    I have a MainController object I am using in COCOA to handle some global application specific tasks which are used in many other classes on my project.

    Right now, I am instantiating that object in Interface Builder and linking it to the rest of the graphical objects through an IBOutlet.

    Two quick questions:

    1) Is there a better way to achieve this? Maybe creating the MainController object by hand and associating it with each class that needs it by code instead of an outlet?

    2) Is there a way to specify the object creation order in InterfaceBuilder? This way, I am going to make sure my MainController object is created before the other objects using it.

    Thanks a lot in advance.
  2. kainjow Moderator emeritus


    Jun 15, 2000
    AFAIK, you can't change the order of how objects load in a NIB. You'll have to do it in code.

    You could just do your initialization in awakeFromNib though.
  3. psantacr thread starter macrumors newbie

    Feb 16, 2008
    Thanks for the quick response. Where should I put that code? On the main function itself? I know how to do it, but I would like to make sure I am doing it the way you are supposed to do it in Cocoa.

    I have been looking around for some code samples on this, but had no luck. Also, there aren't many Open Source COCOA projects to learn from.

    Thanks again. :apple:
  4. kainjow Moderator emeritus


    Jun 15, 2000
    Usually you create an object in MainMenu.nib that is your app delegate. Then, in your app delegate (in code) you can initialize your other objects from a starting point such as init, or applicationDidFinishLaunching.


Share This Page