I can’t say that this is better than Apple docs , so I won’t try. Follow this guide and you must be addressed.
As a side note, there are several memory problems on this line.
self.receivedData = [[NSMutableData alloc] initWithCapacity:[response expectedContentLength]];
You create an NSMutableData object with a hold of count +1 and consider that you have the corresponding getters / setters created with @property (nonatomic, retain) NSMutableData *recievedData , which will add an extra +1.
To solve this problem, one of these two will work (a non-automatic version works best for iphone).
NSMutableData *recievedData = [[NSMutableData alloc] initWithCapacity:[response expectedContentLength]]; self.recievedData = recievedData; [recievedData release]; recievedData= nil;
In addition, I would call
self.recievedData = nil;
instead
[self.recievedData release]
It seems a bit safer and you are using a setter, which is good practice, to get in.
source share