Cocoa document based app.

Joined
Apr 21, 2010
Messages
1
Reaction score
0
Points
1
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?
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
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.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top