Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(I read your comment to the other question)</p> <p>After implementing a few more modules using <code>ASIHTTPRequest</code>, I learned that the best way was to keep a <code>strong</code> reference to your request object. In your case, you can do:</p> <pre><code>self.request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:SOME_URL]]; __weak ASIFormDataRequest *weakRequest = self.request; // __block directive not needed since we only access the instance's properties. [self.request setCompletionBlock:^{ if([weakRequest responseStatusCode] == 200) // ... </code></pre> <p>This way you can still control <code>self.request</code> even after you start the request (e.g. for cancelling). You can do <code>self.request = nil;</code> when you're ready to release your request, maybe inside your completion block or <code>self.request</code>'s parent object's cleanup methods.</p> <p><strong>Update:</strong></p> <p>If you're targeting pre-iOS 5, then the common ground stands: use <code>__unsafe_unretained</code> instead of <code>__weak</code>. This is OK because looking at <code>ASIHTTPRequest.m</code>, the blocks are <code>nil</code>'ed out in its <code>dealloc()</code> (i.e. they shouldn't get executed). Although I haven't tested that yet, so make sure to still test with NSZombies enabled.</p> <p><strong>Note:</strong></p> <p>The only safe way to cancel an <code>ASIHTTPRequest</code> object is to call its <code>clearDelegatesAndCancel</code> method. I've been bitten by some nasty bugs when I was just using the plain <code>cancel</code> one.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload