title: iOS blocks and strong/weak references to self
body: <p>I have a question about strong and weak references to self in blocks in iOS. I know the proper way to refer to self inside a block is to create a weak reference outside the block, and then a strong reference to that weak reference inside the block, like this: </p>
  
  <pre><code>__weak typeof(self) weakSelf = self;
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^ {
      typeof(self) strongSelf = weakSelf;
      NSLog(@"%@", strongSelf.someProperty);
  });
  </code></pre>
  
  <p>However, what happens if you have nested blocks? Is the one set of references enough? Or do you need a new set for each block? For example, which of the following is correct?</p>
  
  <p>This:</p>
  
  <pre><code>__weak typeof(self) weakSelf = self;
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^ {
      typeof(self) strongSelf = weakSelf;
      NSLog(@"%@", strongSelf.someProperty);
      dispatch_async(dispatch_get_main_queue(), ^ {
          strongSelf.view.frame = CGRectZero;
      });
  });
  </code></pre>
  
  <p>Or this:</p>
  
  <pre><code>__weak typeof(self) weakSelf = self;
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^ {
          typeof(self) strongSelf = weakSelf;
          NSLog(@"%@", strongSelf.someProperty);
          __weak typeof(strongSelf) weakSelf1 = strongSelf;
          dispatch_async(dispatch_get_main_queue(), ^ {
              typeof(strongSelf) strongSelf1 = weakSelf1;
              strongSelf1.view.frame = CGRectZero;
          });
      });
  </code></pre>
  
  <p>Any information or explanation is much appreciated!</p>