這是寫這個if if代碼檢查的最好方法嗎?在字典中的語言ID如何以更好的方式檢查代碼?
// set the default to Italy if countrySaved is null
if (lang == NULL) {
lang = @"it";
}
// otherwise set the correct lang based on the country chosed and saved in nsuserdefaults
if ([countrySaved isEqual:@"Brazil"]) {
lang = @"br";
}
else if ([countrySaved isEqual:@"Spain"]) {
lang = @"es";
}
else if ([countrySaved isEqual:@"Italy"]) {
lang = @"it";
}
else if ([countrySaved isEqual:@"United States"]) {
lang = @"us";
}
else if ([countrySaved isEqual:@"United Kingdom"]) {
lang = @"uk";
}
感謝您的幫助
爲了將來的參考,像這樣的問題(用於工作代碼/優化)對於StackExchange站點是完美的:[CodeReview](http://codereview.stackexchange.com/) – jhilgert00