Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

easy switch case problem.... [objective c]

if comment the nslog-line, there is an error:

Semantic Issue: Use of undeclared identifier 'alert'

switch ([[array objectAtIndex:0]intValue]) {
    case 2:
        NSLog(@"Allergie alarm");   << commenting this, gives me an error!!!
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"blabal"
                              message: @"balbalb"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        break;
    default:
        break;
}
like image 214
Phil Avatar asked Jul 19 '26 15:07

Phil


1 Answers

In order to declare a new variable inside a case you need to open a new scope. To open a new scope simply use curly braces as others have already written.

like image 197
DarkDust Avatar answered Jul 21 '26 07:07

DarkDust



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!