Re: A Mac App & helper NSStatusItem - how to share preferences
Re: A Mac App & helper NSStatusItem - how to share preferences
- Subject: Re: A Mac App & helper NSStatusItem - how to share preferences
- From: Steve Cronin <email@hidden>
- Date: Mon, 29 Dec 2008 03:16:05 -0600
Kyle;
Thanks for that pointer! Based on the documentation you cited I've
now got the reading of NSUserDefaults functioning!
In the hopes that it might be useful to someone else, I include these
'Cocoa friendly' methods.
I grant that there are some improvements which could be made, I
include them here in the spirit of helpfulness to the community....
// myBundleID is a static string defined elsewhere
//retrieves the full user defaults dictionary
- (NSDictionary *) prefDictionary {
CFStringRef appBundleID = (CFStringRef)myBundleID;
return (NSDictionary *)CFPreferencesCopyMultiple(NULL, appBundleID,
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
}
//retrieves the string Value of a key [full implementation of all the
CFPropertyList types is left as an exercise for the reader)
- (NSString *) prefStringValueforKey:(NSString *)preferenceKey {
CFStringRef appBundleID = (CFStringRef)myBundleID;
return (NSString*)CFPreferencesCopyValue((CFStringRef)preferenceKey,
appBundleID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
}
//sets the value for a key
- (void) setPrefValue:(id)preferenceValue forKey:(NSString
*)preferenceKey {
CFStringRef appBundleID = (CFStringRef)myBundleID;
CFPreferencesSetValue((CFStringRef)preferenceKey,
(CFPropertyListRef)preferenceValue, appBundleID,
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize(appBundleID, kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
}
Steve
On Dec 28, 2008, at 8:17 PM, Kyle Sluder wrote:
On Sun, Dec 28, 2008 at 8:41 PM, Steve Cronin <email@hidden>
wrote:
This not a managed environment nor is this issue related to users
or hosts,
so it doesn't seem that CFPreferences is called for (or even helps!)
In fact, CFPreferences is exactly what you need. Apple has some
sample code describing how to do exactly what you want:
http://developer.apple.com/documentation/CoreFOundation/Conceptual/CFPreferences/Tasks/UsingLowAPI.html#/
/apple_ref/doc/uid/20001170
--Kyle Sluder
_______________________________________________
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