如何修复 xcode 警告“未使用的表达式结果”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6688764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to fix xcode warning "Expression result unused"
提问by C.Johns
I am doing a registration process with my app where the user enters in a number that I check against my db.. anyway long story short where I pass codeinto my NSString *startURLhave a warning I cannot get rid of, it says
我做一个注册过程与我的应用程序,其中用户在一些进入我核对我的数据库..反正长话短说,我通过代码到我的NSString * startURL有一个警告,我无法摆脱的,它说
"Expression result unused"
“未使用的表达结果”
have you ever experienced anything like this and if so how do I fix it?
你有没有经历过这样的事情,如果有,我该如何解决?
-(void)startRegConnect:(NSString *)tempRegCode{
//tempRegCode = S.checkString;
NSLog(@"tempRegCode from RegConnection =%@",tempRegCode);
NSString *code = [[NSString alloc] initWithString:tempRegCode];
//urlstart string
NSString *startURL = (@"http://188.162.17.44:8777/ICService/?RegCode=%@",code); //warning here
NSURL *url = [NSURL URLWithString:startURL];
//create a request object with that url
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
//clear out the exisiting connection if there is on
if (connectionInProgress) {
[connectionInProgress cancel];
[connectionInProgress release];
}
//Instantiate the object to hold all incoming data
[cookieData release];
cookieData = [[NSMutableData alloc]init];
//create and initiate the connection - non-blocking
connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
回答by jtbandes
You can't just do (@"http://188.162.17.44:8777/ICService/?RegCode=%@",code)
. Use [NSString stringWithFormat:@"http://188.162.17.44:8777/ICService/?RegCode=%@", tempRegCode]
.
你不能只是做(@"http://188.162.17.44:8777/ICService/?RegCode=%@",code)
。使用[NSString stringWithFormat:@"http://188.162.17.44:8777/ICService/?RegCode=%@", tempRegCode]
.
回答by CocoaChris
It's because of the parenthesis. By writing (blabla) it becomes an expression, which you are not using as an expressing, hence the compiler complains.
这是因为括号。通过编写 (blabla) 它变成了一个表达式,您没有将其用作表达式,因此编译器会抱怨。
Change to [NSString stringWithFormat: ...];
and it becomes a method.
更改为[NSString stringWithFormat: ...];
,它成为一种方法。