• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How best to access application-scope objects from documents
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How best to access application-scope objects from documents


  • Subject: Re: How best to access application-scope objects from documents
  • From: "I. Savant" <email@hidden>
  • Date: Thu, 22 Mar 2007 11:16:36 -0400

Paul:

For this problem, I'd just use the NSUserDefaultsController object. It has a convenience class method as follows:

  [NSUserDefaultsController sharedUserDefaultsController];


As for other controllers that do not have such a convenience method ...


Instantiate the the controller in the MainMeu.nib. Make it your application's delegate (drag a connection from File's Owner in the MainMenu.nib to your controller).

  From anywhere in your app you can reference it this way:

   [NSApp delegate];

If you want to have more than one controller, connect those controllers to your app delegate (by creating outlets on your app delegate that point to the controllers and dragging appropriate connections). Then write a method in your delegate like this:

- (id)fooController
{
    return myFooController;
}

  ... then you can access it like this:

  [[NSApp delegate] fooController];

  Hope this helps.

--
I.S.


On Mar 22, 2007, at 5:48 AM, Paul Thomas wrote:

Hi,

this is really a question about best practise in Document Architecture designs which are NIB based.

I'm adding a preferences controller to my application to manage all of the NSUserDefaults and also control a preferences window. This is all going swimmingly but, being a little new to the whole NIB- based thing, I'm not sure how the document objects should be accessing this controller.

The controller is instantiated by the MainMenu NIB - but it isn't hooked up to anything except the menu. So far as I can see, I can either look through the top level objects or add an outlet to the application delegate (prefer the later). But then I have to get the reference to the documents. Do I need to subclass the document controller to pass it to the initialiser, or is it better to 'reach back' and traverse the object graph from doc through app to the delegate. They both seem a bit messy unless I've missed something.

cheers,
paul.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How best to access application-scope objects from documents (From: Paul Thomas <email@hidden>)

  • Prev by Date: Re: Need help setting up KVO
  • Next by Date: [NSTableView] Tooltip and reloadData: bug or feature?
  • Previous by thread: How best to access application-scope objects from documents
  • Next by thread: sending image through network
  • Index(es):
    • Date
    • Thread