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
  • 34,719
  • 24
  • 185
  • 251
Weston
  • 1,463
  • 1
  • 11
  • 30

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,402
  • 6
  • 62
  • 70