약한 포인터와 강한 포인터의 차이를 제대로 이해하지 못합니다. 지금까지 큰 문제는 발생하지 않았습니다. 문서의 예제를 따라 NSURLRequest를 만들고 NSURLConnection에서 데이터를 수신하는 데 사용하고 있습니다.NSData에 약한 포인터가 NSURLConnection을 사용하여 데이터를 읽을 수 없습니까?
코드는 다음과 같다 :
//create the request with url
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:3000/students.json"]];
//create the with the request
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if (connection) {
//create NSData instance to hold data if connection is successfull
self.receivedData = [[NSMutableData alloc]init];
// NSLog(@"%@",@"Connection successfully");
}
else{
NSLog(@"%@",@"Connection failed");
}
가 SO I 대리인 메소드의 본문
receivedData
에 데이터를 추가.
@property (strong,nonatomic) NSMutableData *receivedData;
//delegate method
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[self.receivedData appendData:data];
NSLog(@"%@",@"Receiving Data");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Succeeded! Received %d bytes of data",[self.receivedData length]);
}
내가 위의 게시 된 코드는 노력하고 있습니다 :) 난 그냥가 고정되어 있기 때문이다.
내 질문은입니다. 포인터 유형이 원래 weak
입니다. 내가 weak
에서 strong
으로 포인터 유형을 바꾸기 전에 항상 [self.receivedData length]
에서 0 바이트의 데이터를 얻을 것이고 나는 왜 그럴 수 없는지 이해할 수 없다. 데이터를 보유하고있다.
좋은 답변 : 감사 – code4j