0

Why this code gives me the following errors?

"use of undeclared identifier baseURL"

and

"Unexpected Interface name NSString, expected expression"

here is the entire block of code

switch (type) {
    case 1:
        NSString *baseURL = [NSString stringWithString:@"http://www.myserver.net/somephp/"];
        NSString *finalURL = [baseURL stringByAppendingString:@"?i="];
        break;
    case 2:
        NSString *finalURL = [baseURL stringByAppendingString:@"?n="];
        break;
    default:
        break;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Weston
  • 1,481
  • 1
  • 11
  • 31

1 Answers1

2

Sounds like those lines are within a switch statement. If this is the case, move the declaration of the strings outside the switch statement.

NSString *baseURL;
NSString *finalURL;
switch (<expression>) {
    case <constant>:
        baseURL = [NSString stringWithString:@"http://www.myserver.net/somephp"];
        finalURL = [baseURL stringByAppendingString:@"?i="];
        break;
    default:
        break;
}

More information and other techniques to work around this on this question.

Community
  • 1
  • 1
albertamg
  • 28,492
  • 6
  • 64
  • 71