I'm currently trying to write an iPhone companion to a website that I'm developing. I'm trying to get JSON data from my website by making a controller a delegate of the NSURLConnection. Here's the problem though, I have an NSMutableData object named responseData initialized like so:
responseData = [NSMutableData dataWithLength:0];
And I want to append data as it comes:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
However, this causes my app to crash and says in the console:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFArray appendData:]: unrecognized selector se开发者_高级运维nt to instance
0x6d0a640'
I'm pretty confident that appendData should be recognized, so I'm at a loss as to what the problem is here...
You have to retain the object:
responseData = [NSMutableData dataWithLength:0];
[responseData retain];
But that's not the common way of doing this. Simply use alloc/init:
responseData = [[NSMutableData alloc] init];
But don't forget to release in dealloc:
[responseData release];
精彩评论