1. Objective C / Говнокод #10310

    −88

    1. 1
    2. 2
    3. 3
    4. 4
    NSString *error = [NSString stringWithFormat:@"Enter your %@%@%@", 
    											 [email length] ? @"" : @"email",
    											 [email length] || [password length] ? @"" : @" and ",
    											 [password length] ? @"" : @"password"];

    Дай дураку тернарный оператор - он и лоб расшибет.

    Запостил: byss, 17 Мая 2012

    Комментарии (1) RSS

    • [code=objective-c]
      - (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]

      Предложите свой код.
      Ответить

    Добавить комментарий