iOS : Why am I getting 'Unused variable' in Xcode?

I'm coding to display a 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

Where is the problem?


It is because you don't do anything with key. You simply alloc and init it, but never really use it.

You could do something like NSLog(@"%@",key); and the error will go away.

The other option is to set Unused Variables to warnings. Go to your project target, Build settings, then find the below image and change Unused Variables to Yes. This will change it from and error to a warning.

Need Your Help

Image not dispaly in TableView in json parsing in ios?

ios objective-c json uitableview uiimageview

I am trying to show the image in UITableViewCell but image not displaying using prototype cell