httpController.h 中的一些代码如下:
@interface httpController:NSObject{
...
NSMutableData *receivedData;
}
@property (nonatomic,retain) NSMutableData *receivedData;
httpController.m 文件中的一些代码如下:
@implementation httpController
@synthesize receivedData;
...
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (!receivedData) {
receivedData = [[NSMutableData alloc] init];
}
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
}
然后我想在 main.m 文件中使用 receivedData,如下所示:
int main(int argc, const char *argv[])
{
HttpController *httpController = [[HttpController alloc] init];
NSURLRequest *request = ...;
NSURLConnection *connetion = ...;
if(connection)
{
NSMutableData *_receviedData = httpController.receivedData;
NSString * dataString = [[[NSString alloc] initWithData:_receviedData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"%@",dataString);
}
[[NSRunLoop currentRunLoop] run];
}
但是我发现在main()函数中,_receivedData的值是空的,并且有注释输出。任何人都可以告诉我有什么问题吗?