Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

psantacr

macrumors newbie
Original poster
Feb 16, 2008
15
0
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.
:eek:
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

psantacr

macrumors newbie
Original poster
Feb 16, 2008
15
0
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.

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:
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.

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.

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.

http://osx.hyperjeff.net/Apps/CocoaSource.html
http://www.cocoadev.com/index.pl?CocoaOpen
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.