|
|
How to write user defaults to another defaults "suite"
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
I've written an application that interacts with the Address Book database, and as such needs to read the Address Book preferences. I've been doing this manually, but recently discovered the NSUserDefaults methods "addSuite" and "removeSuite" which allow me to use shared preference files.
I'll try that, but I'm sure it will make things a bit easier for reading the prefs.
Now I want to actually modify one of the preference settings. I figure I can get my application to execute a shell script command along the lines of:
defaults write <suite> <key> <value>
(which certainly does the job), but I'd like to use a nicer Cocoa way of doing this rather than invoking a unix shell.
Does anyone know how I should go about writing preferences to another applications preferences suite using Cocoa/Objective-C?
(
Last edited by Brass; Mar 18, 2003 at 10:53 PM.
)
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Suites aren't what you're looking for. *waves hand in a Jedi-like manner* The new suite-related methods let you create and remove defaults domains that aren't tied to a particular application, but you access these domains like you would any other.
Here's what you're looking for:
Code:
NSMutableDictionary *addressBookDefaults;
addressBookDefaults = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.AddressBook"] mutableCopy];
[addressBookDefaults setObject:@"us" forKey:@"ABDefaultAddressCountryCode"];
[[NSUserDefaults standardUserDefaults] setPersistentDomain:addressBookDefaults forName:@"com.apple.AddressBook"];
[addressBookDefaults release];
Substitute the specific key and value you're dealing with, of course.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Rickster,
Thanks, that's exactly what I was looking for. I had seen the "persistentDomainForName" method in the documentation, but must have misinterpretted it's use as I was quickly looking through the doco.
And good guess That's exactly the key/value pair I was going to be replacing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|