If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Welcome to Mac-Forums! Join us to comment and to customize your site experience! Members have access to different forum appearance options, and many more functions.

I am creating a document based cocoa app. Each document needs to reference a central object to retrieve some of its data. I have all the Documents working and displaying nicely, but where do I create the central object?

I suppose I need to create some kind of delegate of the Application? But I'm completely lost how to do that. Any offers?

Might depend on what you are doing, but the common case is user preferences and defaults. Look for samples that use NSUserDefaults.

I'm still grasping much of this too, but...

You would create a delegate object for your application (ofter referred to in samples as AppController), and instantiate that in IB and set it as the "File's Owner" delegate. In this object you you create your special object upon startup. You could then get to it by

Code:

[[NSApp delegate] myCustomerGlobalObjectNameiVar]

NSApp is a global variable that points to your applications instance of NSApplication.

Do not retain or release that object in your documents. They don't own it. You can assign it to a local variable if you want.

You may think it a good idea to use the delegate as your object, but the delegate can be responsible for many things and is capable of responding to many optional delegated methods from the NSApp instance. It is a general purpose object that helps you control your application.