- 1
- 2
- 3
- 4
NSString *error = [NSString stringWithFormat:@"Enter your %@%@%@",
[email length] ? @"" : @"email",
[email length] || [password length] ? @"" : @" and ",
[password length] ? @"" : @"password"];
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−88
NSString *error = [NSString stringWithFormat:@"Enter your %@%@%@",
[email length] ? @"" : @"email",
[email length] || [password length] ? @"" : @" and ",
[password length] ? @"" : @"password"];
Дай дураку тернарный оператор - он и лоб расшибет.
guest 20.10.2012 11:46 # 0
- (void)printErrorWithEmail:(NSString *)email pasword:(NSString *)password
{
NSString *error = [NSString stringWithFormat:@"Enter your %@%@%@",
[email length] ? @"" : @"email",
[email length] || [password length] ? @"" : @" and ",
[password length] ? @"" : @"password"];
NSLog(@"error: %@", error);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDiction ary *)launchOptions
{
[self printErrorWithEmail:@"Test" pasword:@"hg83kd6"];
[self printErrorWithEmail:@"" pasword:@"hg83kd6"];
[self printErrorWithEmail:nil pasword:@"hg83kd6"];
[self printErrorWithEmail:@"Test" pasword:@""];
[self printErrorWithEmail:@"Test" pasword:nil];
[self printErrorWithEmail:@"" pasword:@""];
[self printErrorWithEmail:nil pasword:@""];
[self printErrorWithEmail:@"" pasword:nil];
[self printErrorWithEmail:nil pasword:nil];
return YES;
}
Output>
error: Enter your
error: Enter your email
error: Enter your email
error: Enter your password
error: Enter your password
error: Enter your email and password
error: Enter your email and password
error: Enter your email and password
error: Enter your email and password
[/color]
Предложите свой код.