2012-09-10 29 views
0

我编码显示PHPechoiOS:为什么我在Xcode中获得'Unused variable'?

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]; 

当我编译,我有这样的警告消息:Unused variable key

问题出在哪里?

回答

5

这是因为你没有做任何事情key。你只需简单地分配和初始化它,但从来没有真正使用它。

你可以做一些像NSLog(@"%@",key);这样的错误会消失。

另一个选项是将Unused Variables设置为警告。转到您的项目目标,构建设置,然后找到下面的图像并将Unused Variables更改为Yes。这会将它从错误改为警告。

enter image description here

+0

谢谢!没关系 :) – user1659987

0

在最后一行要指定键的值,但你永远不使用它。您可以将其配置为不抛出错误,但如果不使用变量则会发出警告。否则只是注释掉键的分配。

0

如果您不需要使用密钥,只需将其注释掉由//

// NSString *key = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil] encoding:NSUTF8StringEncoding]; 
相关问题