开发者

Issue with NSString and concatenation

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜