我是iphone編程新手。請解釋我這個代碼。那就是使用standardUserDefaults?這個代碼如何工作?standardUserDefaults有什麼用?
-(void)load
{
DLog("Load Configuration");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
bool savedDefaults = [defaults boolForKey:kKeySavedDefaults];
if (savedDefaults)
{
columns = [defaults integerForKey:kKeyColumns];
if (columns == 0) columns = kColumnsDefault;
rows = [defaults integerForKey:kKeyRows];
if (rows == 0) rows = kRowsDefault;
photoType = [defaults integerForKey:kKeylastPhotoType];
photoEnabled = [defaults boolForKey:kKeyPhotoEnabled];
numbersEnabled = [defaults boolForKey:kKeyNumbersEnabled];
soundEnabled = [defaults boolForKey:kKeySoundEnabled];
}
else
{
columns = kColumnsDefault;
rows = kRowsDefault;
photoType = klastPhotoTypeDefault;
photoEnabled = kPhotoEnabledDefault;
numbersEnabled = kNumbersEnabledDefault;
soundEnabled = kSoundEnabledDefault;
}
}
-(void)save
{
DLog("Save Configuration");
BOOL restart = NO;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults integerForKey:kKeyColumns] != columns) { restart = YES; }
if ([defaults integerForKey:kKeyRows] != rows) { restart = YES; }
[defaults setBool:YES forKey:kKeySavedDefaults];
[defaults setInteger:columns forKey:kKeyColumns];
[defaults setInteger:rows forKey:kKeyRows];
[defaults setInteger:photoType forKey:kKeylastPhotoType];
[defaults setBool:photoEnabled forKey:kKeyPhotoEnabled];
[defaults setBool:numbersEnabled forKey:kKeyNumbersEnabled];
[defaults setBool:soundEnabled forKey:kKeySoundEnabled];
[defaults synchronize];
[board configChanged:restart];
}
我的密碼存儲在一個簡單,坦率的plist存放一些少量的像用戶名的數據,密碼......?我只是希望我不使用你的一個應用程序oO – JustSid
更好地使用密鑰鏈來獲取密碼。 – jcm