Created
December 1, 2009 02:13
-
-
Save ejknapp/246002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//NSUserDefaults usage for user and app settings | |
- (void)createUserDefaultsFromPlist { | |
NSString *settingsPlistPath = [[NSBundle mainBundle] | |
pathForResource:@"FlakSettings" ofType:@"plist"]; | |
NSDictionary *dictionaryFromDefaultPlist; | |
if (settingsPlistPath) { | |
dictionaryFromDefaultPlist = [NSMutableDictionary | |
dictionaryWithContentsOfFile:settingsPlistPath]; | |
} | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
[defaults setObject:[dictionaryFromDefaultPlist objectForKey:@"currentHostURL"] | |
forKey:@"currentHostURL"]; | |
[defaults setObject:[dictionaryFromDefaultPlist objectForKey:@"savedHosts"] | |
forKey:@"savedHosts"]; | |
[defaults setObject:[dictionaryFromDefaultPlist objectForKey:@"loginData"] | |
forKey:@"loginData"]; | |
} | |
- (id)init { | |
if (self = [super init]) { | |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; | |
NSString *currentHostURL = [userDefaults stringForKey:@"currentHostURL"]; | |
//Load bundle plist if settings file doesn't exist | |
if (currentHostURL == nil) { | |
NSLog(@"User defaults not found so setting them from plist"); | |
[self createUserDefaultsFromPlist]; | |
} else { | |
NSLog(@"User defaults set so nothing to do"); | |
} | |
} | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment