• 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: NSUserDefaults per Document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaults per Document


  • Subject: Re: NSUserDefaults per Document
  • From: Jens Miltner <email@hidden>
  • Date: Tue, 2 Oct 2007 09:26:43 +0200


Am 29.09.2007 um 17:34 schrieb Sanford Selznick:

Hello,

I have a set of preferences that display in a sheet on a document window. The preferences are saved /for/ the document on that machine, but not /in/ the document itself. Each of my documents contains a UUID I can to use to key the preferences for that document.

I'd like to use all the goodness of NSUserDefaults and IB bindings to set the controls on the sheet. Perhaps with some sort of dictionary in the NSUserDefaults for each document? How do I specify this dictionary as the defaults for the sheet?

I've read the archives, Apple's documentation and I don't quite see how to do this.

You could implement a getter and setter for the prefs dictionary in your document controller (via NSUserDefaults, retrieving the dictionary for the document GUID). Then, instead of binding to the shared user defaults, bind to your document controller with the path prefixed with your getter method, e.g.


@interface MyDocumentController {
}

- (id)documentPrefs;
- (void)setDocumentPrefs:(id)prefs;

@end

@implementation MyDocumentController
- (id)documentPrefs
{
return [[NSUserDefaults standardUserDefaults] objectForKey:[self documentID]];
}
- (void)setDocumentPrefs:(id)prefs
{
return [[NSUserDefaults standardUserDefaults] setObject:prefs forKey: [self documentID]];
}
@end




then bind to your document controller with path "documentPrefs.<key>".

Not a "pure" bindings implementation as you need to write that little glue code that will get and set the prefs for a given document, but still only about 2 real lines of code ;-)

HTH,
</jum>


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


  • Prev by Date: Re: Where are the boundaries of Cocoa and how are the boundaries perceived ?
  • Next by Date: Re: How can we draw a NSWindow in a custom NSView?
  • Previous by thread: Cocoaheads Lake Forest meets at 7pm, as the body said, not 10pm, like the subject said.
  • Next by thread: Re: NSUserDefaults per Document
  • Index(es):
    • Date
    • Thread