Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (55 sloc) 1.777 kb
a273a1d @alinx use own plist with bundleID
alinx authored
1 //
2 // BundleUserDefaults.m
3 //
4 // Created by John Chang on 6/15/07.
5 // This code is Creative Commons Public Domain. You may use it for any purpose whatsoever.
6 // http://creativecommons.org/licenses/publicdomain/
7 //
8
9 #import "BundleUserDefaults.h"
10
11
12 @implementation BundleUserDefaults
13
14 - (id) initWithPersistentDomainName:(NSString *)domainName
15 {
16 if ((self = [super init]))
17 {
18 _applicationID = [domainName copy];
19 _registrationDictionary = nil;
20
21 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
22 }
23 return self;
24 }
25
26 - (void) dealloc
27 {
28 [[NSNotificationCenter defaultCenter] removeObserver:self];
29
30 [_applicationID release];
31 [_registrationDictionary release];
32 [super dealloc];
33 }
34
35
36 - (void) _applicationWillTerminate:(NSNotification *)notification
37 {
38 [self synchronize];
39 }
40
41
42 - (id)objectForKey:(NSString *)defaultName
43 {
44 id value = [(id)CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)_applicationID) autorelease];
45 if (value == nil)
46 value = [_registrationDictionary objectForKey:defaultName];
47 return value;
48 }
49
50 - (void)setObject:(id)value forKey:(NSString *)defaultName
51 {
52 CFPreferencesSetAppValue((CFStringRef)defaultName, (CFPropertyListRef)value, (CFStringRef)_applicationID);
53 }
54
55 - (void)removeObjectForKey:(NSString *)defaultName
56 {
57 CFPreferencesSetAppValue((CFStringRef)defaultName, NULL, (CFStringRef)_applicationID);
58 }
59
60
61 - (void)registerDefaults:(NSDictionary *)registrationDictionary
62 {
63 [_registrationDictionary release];
64 _registrationDictionary = [registrationDictionary retain];
65 }
66
67
68 - (BOOL)synchronize
69 {
70 return CFPreferencesSynchronize((CFStringRef)_applicationID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
71 }
72
73 @end
Something went wrong with that request. Please try again.