iOS and ARC : How to retain self during asynchronous operations? <p>It's the first time I'm fiddling around with iOS5 and ARC. So far, so good, it works, but I've run into some kind of a problem.</p> <p>I have a custom <code>UIStoryboardSegue</code> in which I use Facebook Connect (or other services) to log the user into my app. Simply put, it should do the following :</p> <ol> <li>User clicks on the button</li> <li>Button fires the Segue</li> <li>The segue starts asynchronous login but does not immediately push the view controller</li> <li>If, and only if the login is successful, the segue pushes the view controller</li> </ol> <p>What happens instead, is that the login starts, but the segue is immediately released by ARC before it has any chance to complete.</p> <p>I thought of a quick'n'dirty hack to prevent this:</p> <pre class="lang-c prettyprint-override"><code>@interface BSLoginSegue() { __strong BSLoginSegue *_retained_self; } @end // Stuff... // Other stuff... - (void) perform { login(); _retained_self = self; } - (void) loginServiceDidSucceed:(BSLoginService *)svc { ... _retained_self = nil; } </code></pre> <p>The thing is, it <em>really</em> is <em>a hack</em>, so I was wondering if there were any other, and more elegant way I could do the same?</p>