Thread: Cocoa document based app.
04-22-2010, 01:14 AM #1
Cocoa document based app.
- Member Since
- Apr 21, 2010
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?
04-22-2010, 06:28 PM #2
- Member Since
- Jun 25, 2005
- On the road
- 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
[[NSApp delegate] myCustomerGlobalObjectNameiVar]
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.CameraTime - Time lapse photography for novice and advanced users.
When asking questions, post the version of your software. You'll receive better answers.
Please post your results to the thread as it is good feedback.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By dede94 in forum OS X - Development and DarwinReplies: 7Last Post: 05-16-2012, 08:01 AM
By Leigh in forum OS X - Development and DarwinReplies: 0Last Post: 11-26-2008, 01:04 PM
By macornot in forum OS X - Development and DarwinReplies: 0Last Post: 06-06-2008, 03:50 AM
By giulio in forum OS X - Development and DarwinReplies: 0Last Post: 03-31-2008, 04:55 PM
By remain in forum OS X - Apps and GamesReplies: 0Last Post: 05-22-2007, 08:55 AM