Results 1 to 2 of 2
  1. #1

    Member Since
    Apr 21, 2010
    Cocoa document based app.
    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?

  2. #2

    xstep's Avatar
    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]
    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.
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calendar interface for cocoa app
    By dede94 in forum OS X - Development and Darwin
    Replies: 7
    Last Post: 05-16-2012, 09:01 AM
  2. Replies: 0
    Last Post: 11-26-2008, 02:04 PM
  3. Word document on Mac based browser
    By macornot in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 06-06-2008, 04:50 AM
  4. Any cocoa developers for hire (project based)?
    By giulio in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 03-31-2008, 05:55 PM
  5. Ways to tell the difference between a Cocoa app and a Carbon app
    By remain in forum OS X - Apps and Games
    Replies: 0
    Last Post: 05-22-2007, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts