title: EXC_BAD_ACCESS when passing NSString to method from within a block
body: <p>I have a method which requests access to Twitter, and then sets the username using <code>- (void) setUsername:(NSString *)username</code>. I have to pass <code>ACAccountStore.requestAccessToAccountsWithType...</code> a completion handler (block) as follows:</p>
  
  <pre><code>[self.accounts requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *actualError) {
      if(granted == YES) {
          self.haveTwitterAccess = YES;
          ACAccount *account = [self.accounts accountsWithAccountType:twitterAccountType][0];
          [self setUsername: account.username];
  
  // [...]
  </code></pre>
  
  <p>When I do this, however, I get <code>EXC_BAD_ACCESS</code> in the <code>setUsername</code> method (to which I'm trying to pass <code>account.username</code>). If I try <code>NSLog(@"%@", account.username);</code> then I can see that the value is correct, but when passed to <code>setUsername</code>, the <code>username</code> variable is <code>nil</code>.</p>
  
  <p>I imagine that it is being released in between the threads somewhere here, but am not sure, what with all this new ARC stuff, how to stop it happening. In essence, this boils down to passing strings between threads I suppose?</p>
  
  <p>I've tried things like <code>[account.username copy]</code> and setting the accounts store as <code>retain</code> etc., but nothing seems to work. I've also tried referencing <code>self</code> using:</p>
  
  <pre><code>__block UserManager *blockSafeSelf = self;
  </code></pre>
  
  <p>How to I ensure that the variable passed from within a callback block to a method on another object is retained?</p>
  
  <h3>EDIT:</h3>
  
  <p>This is in a class called <code>UserManager</code> which has a property</p>
  
  <pre><code>@property (nonatomic) ACAccountStore *accounts;
  </code></pre>
  
  <p>which deals with the Twitter access. It also has the method:</p>
  
  <pre><code>- (void) setUsername: (NSString *) username;
  </code></pre>
  
  <p>which I'm trying to call with the account username inside the completion block. I hope that helps pinpoint the issue a bit better.</p>
  
  <h3>EDIT (2):</h3>
  
  <p><code>username</code> is a property of <code>UserManager</code> and is declared as follows:</p>
  
  <pre><code>@property (nonatomic) NSString *username;
  </code></pre>