[英]iOS : Why am I getting 'Unused variable' in Xcode?
I'm coding to display a php echo
我正在编码以显示php
echo
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setTimeoutInterval:180.0];
[request setURL:[NSURL URLWithString:@"http://localhost:8888/MAMP/signup/getkey.php"]];
[request setHTTPMethod:@"POST"];
NSString *key = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
When I compile, I have this warning message : Unused variable key
编译时,出现以下警告消息:
Unused variable key
Where is the problem? 问题出在哪儿?
It is because you don't do anything with key
. 这是因为您对
key
不执行任何操作。 You simply alloc and init it, but never really use it. 您只需分配和初始化它,但从未真正使用过它。
You could do something like NSLog(@"%@",key);
您可以执行类似
NSLog(@"%@",key);
and the error will go away. 错误就会消失。
The other option is to set Unused Variables
to warnings. 另一个选项是将“
Unused Variables
设置为警告。 Go to your project target, Build settings, then find the below image and change Unused Variables
to Yes
. 转到项目目标“构建设置”,然后找到下图并将“
Unused Variables
Yes
更改为“ Yes
。 This will change it from and error to a warning. 这会将其从错误更改为警告。
On the last line you are assigning key to a value but you never use it. 在最后一行,您正在将键分配给一个值,但是您从未使用过它。 You can configure it to not throw an error, but rather a warning if you do not use a variable.
您可以将其配置为不引发错误,而是在不使用变量的情况下发出警告。 Otherwise just comment out the assignment of key.
否则,只需注释掉密钥分配。
如果您不需要使用该键,只需用//将其注释掉
// NSString *key = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.