NSUserDefaultsController
NSUserDefaultsController
- Subject: NSUserDefaultsController
- From: James Spencer <email@hidden>
- Date: Sat, 8 Nov 2003 15:05:43 -0600
I'm obviously missing something. Just playing around with the new
NSUserDefaultsController and setting up a preferences window using it.
Using the example in Apple's documentation, I had no problem getting my
Preferences window to work and getting my preferences to be displayed
in user interface elements of other windows.
What I can't figure out for the life of me is how I access a
preferences item other than through an interface widget set up
Interface Builder. For example, my application needs to send an email
message which I create and send using Pantomime. To make this work, I
need the user to provide his or her SMTP server which I collect in a
text field in my Preferences window. How do I get that information
back out of my user preferences? I apparently can get the object
that NSUserDefaultsController stored with:
NSData * tempData = [[[NSUserDefaultsController
sharedUserDefaultsController]
defaults] valueForKey:@"smtpServer"];
but what is returned is a data object and I can't figure out how to
convert this object back into my NSString. I've tried:
[[NSValueTransformer
valueTransformerForName:NSUnarchiveFromDataTransformerName]
reverseTransformedValue:tempData];
but this doesn't work nor does any other permutation that I've tried.
I can get the string
put back into a text field in any window I choose by setting up the
appropriate binding in IB and I could then, of course, recover the
string from the text field but as I have no reason to put it into the
field other than to take it out, I would really rather not. In fact,
I've got to believe there is a better way because if not, this
certainly would not be an improvement over the old method of saving and
accessing user preferences.
Any ideas?
Spence
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.