I have a two classes, a controller called "AppController" and a class called "URLDelegate" that encapsulates the sample NSURL code from Apple's URL Loading System Programming Guide.
The guide repeatedly mentions declaring the receivedData instance variable "elsewhere." I assume this means outside of the URLDelagate class, because if I declare it in the URLDelegate class, my controller class can't "see" the data that has been downloaded.
I know that data is received, because in my connectionDidFinishLoading function, I have NSLog display the results:
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
receivedText=[[NSString alloc] initWithData:receivedData encoding: NSASCIIStringEncoding];
NSLog(@"receivedText=%@",receivedText);
So I'm a bit stumped with the following questions:
- Where should I declare receivedData? My controller class? A third class?
- Can I just declare it like any normal NSMutableData variable?
- How do I give my URLDelegate class "access" to this variable? E.g., if I declare receivedData in my AppController class, wouldn't I have to instantiate AppController within URLDelegate? But how would this possible if it's the AppController class which is instantiating the URLDelegate class in the first place?
Especially with regard to the last question, I feel like I must be overlooking something blindingly obvious and fundamental. If anyone could point me in the right direction, I would really appreciate it.
Thank you!
Update: I moved all of the NSURL functions out of their URLDelegate class and placed them in my controller class. I'm now able to update variables in my controller class from the connectionDidFinishLoading. This seems a bit hacky to me, but it works.