title: iOS 5 Twitter Framework & completionHandler block - "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
body: <p>I am very new to programming and Objective-C and I am trying to work out what is wrong with my code. I have read a bit about blocks but I don't know how any of what I have read so far is relevant to my code. </p>
  
  <p>My code is using the iOS 5 Twitter Framework. I use most of the sample code that Apple provides so I actually had no clue at first that I was using a block for the completion handler.</p>
  
  <p>Now I get those two messages from Xcode 4 saying "<em>1. Block will be retained by an object strongly retained by the captured object</em>" and "<em>Capturing 'self' strongly in this block is likely to lead to a retain cycle</em>". </p>
  
  <p>Basically, what I did is to remove the code Apple used in their completion handler (switch statement with TWTweetComposeViewControllerResultCancelled &amp; TWTweetComposeViewControllerResultDone) and used my if statements with <code>[imagePickerController sourceType]</code>.</p>
  
  <p>So the <code>sendTweet</code> gets called after an image has been added to the tweet. </p>
  
  <p>I hope someone can explain to me why this is happening and how I can solve it. Also: can I put the completion handler code into a method instead of a block?</p>
  
  <pre><code>- (void)sendTweet:(UIImage *)image
  {
      //adds photo to tweet
      [tweetViewController addImage:image];
  
      // Create the completion handler block.
      //Xcode: "1. Block will be retained by an object strongly retained by the captured object"
      [tweetViewController setCompletionHandler:
                               ^(TWTweetComposeViewControllerResult result) {
              NSString *alertTitle,
                       *alertMessage,
                       *otherAlertButtonTitle,
                       *alertCancelButtonTitle;
  
              if (result == TWTweetComposeViewControllerResultCancelled) 
              {
                  //Xcode: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
                  if ([imagePickerController sourceType])
                  {
                      alertTitle = NSLocalizedString(@"TCA_TITLE", nil);
                      alertMessage = NSLocalizedString(@"TCA_MESSAGE", nil);
                      alertCancelButtonTitle = NSLocalizedString(@"NO", nil);
                      otherAlertButtonTitle = NSLocalizedString(@"YES", nil);
  
                      //user taps YES
                      UIAlertView *alert = [[UIAlertView alloc] 
                                               initWithTitle:alertTitle 
                                                     message:alertMessage 
                                                    delegate:self   // Note: self
                                           cancelButtonTitle:alertCancelButtonTitle 
                                           otherButtonTitles:otherAlertButtonTitle,nil];
                      alert.tag = 1;
                      [alert show];                
                  }            
              }
  </code></pre>