Как я могу сделать мой следующий код "DRY" (Dont Repeat Yourself)Как я могу сделать следующий код сухим?
- (void)updateLetterScore { // NOT DRY... Must fix
if (percentScore < 60.0)
letterLabel.text = [NSString stringWithFormat:@"F"];
if (percentScore > 59.0 && percentScore < 64.0)
letterLabel.text = [NSString stringWithFormat:@"D-"];
if (percentScore > 64.0 && percentScore < 67.0)
letterLabel.text = [NSString stringWithFormat:@"D"];
if (percentScore > 66.0 && percentScore < 70.0)
letterLabel.text = [NSString stringWithFormat:@"D+"];
if (percentScore > 69.0 && percentScore < 74.0)
letterLabel.text = [NSString stringWithFormat:@"C-"];
if (percentScore > 73.0 && percentScore < 76.0)
letterLabel.text = [NSString stringWithFormat:@"C"];
if (percentScore > 76.0 && percentScore < 80.0)
letterLabel.text = [NSString stringWithFormat:@"C+"];
if (percentScore > 79.0 && percentScore < 84.0)
letterLabel.text = [NSString stringWithFormat:@"B-"];
if (percentScore > 83.0 && percentScore < 86.0)
letterLabel.text = [NSString stringWithFormat:@"B"];
if (percentScore > 85.0 && percentScore < 90.0)
letterLabel.text = [NSString stringWithFormat:@"B+"];
if (percentScore > 89.0 && percentScore < 94.0)
letterLabel.text = [NSString stringWithFormat:@"A-"];
if (percentScore > 93.0 && percentScore < 100.0)
letterLabel.text = [NSString stringWithFormat:@"A"];
if (percentScore == 100)
letterLabel.text = [NSString stringWithFormat:@"A+"];
}
Спасибо за советы. Я просто хочу знать, что вы, ребята, думаете, потому что этот маленький снипп выглядит в моем коде HORRENDOUS.
Игнорирование основного вопроса, почему на erath вы используете + stringWithFormat :? Ни одна из ваших строк не имеет никакой информации о форматировании вообще, поэтому просто назначьте строку. например letterLabel.text = @ "A"; –