如何修复 xcode 警告“表达式结果未使用”
我正在使用我的应用程序进行注册过程,其中用户输入一个数字,我会根据我的数据库进行检查..无论如何,长话短说,我将 code 传递到我的 NSString *startURL 中> 有一个我无法摆脱的警告,它说
“表达式结果未使用”
您是否经历过类似的事情,如果是的话我该如何解决?
-(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];
}
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 code into my NSString *startURL have a warning I cannot get rid of, it says
"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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能只执行
(@"http://188.162.17.44:8777/ICService/?RegCode=%@",code)
。使用[NSString stringWithFormat:@"http://188.162.17.44:8777/ICService/?RegCode=%@", tempRegCode]
。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]
.就是因为括号的原因。通过编写 (blabla) 它成为一个表达式,您没有将其用作表达式,因此编译器会抱怨。
更改为
[NSString stringWithFormat: ...];
它就变成了一个方法。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.
Change to
[NSString stringWithFormat: ...];
and it becomes a method.