开发者

Issue with NSString and concatenation

开发者 https://www.devze.com 2023-03-04 21:38 出处:网络
Why this code gives me the following errors? \"use of undeclared identifier baseURL\" and \"Unexpected Interface name NSString, expected expression\"

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 s开发者_如何学运维tringWithString:@"http://www.myserver.net/somephp/"];
        NSString *finalURL = [baseURL stringByAppendingString:@"?i="];
        break;
    case 2:
        NSString *finalURL = [baseURL stringByAppendingString:@"?n="];
        break;
    default:
        break;
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消