我打算優化我的代碼並改進我的編程。我正在看這個不斷更新的聲明。有沒有更好的方式來寫這個調用到許多NSUserDefault BOOLS?
有沒有更好的方法來調用衆多的BOOLS
?是否可以將它們包含在FOR
聲明中?
baseballHat = [[NSUserDefaults standardUserDefaults] boolForKey:
@"baseballHat"];
asianHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"asianHat"];
cowboyHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"cowboyHat"];
topHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"topHat"];
partyHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"partyHat"];
sumbreroHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"sumbreroHat"];
wizardHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"wizardHat"];
beretHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"beretHat"];
pirateHat = [[NSUserDefaults standardUserDefaults] boolForKey: @"pirateHat"];
vikingHelmet = [[NSUserDefaults standardUserDefaults] boolForKey: @"vikingHelmet"];
if(baseballHat == YES){
_baseballWearBut.visible = YES;
_baseballHatOwned.visible = YES;
}
if(topHat == YES){
//Continue with if statements