我试图避免这个警告正在使用NSURLConnection
:
-(void)goGetData{
responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://somefile.php"]];
[[NSURLConnection alloc]initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
//label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
NSLog(@"Connection failed: %@",error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSMutableArray *qnBlock = [responseString JSONValue];
for (int i = 0; i < [qnBlock count]; i++){
NSLog(@"%@",[qnBlock objectAtIndex:i]);
}
}
警告在线:
[[NSURLConnection alloc]initWithRequest:request delegate:self];
警告是:
Expression result unused.
整个代码运行良好,但我只是采取预防措施。