title: Anonymous delegate implementation in Objective-C?
body: <p>Is it possible to declare anonymous implementations of things like Delegates in Objective-C. I think I have the terminology right, but here's a java example:</p>
  
  <pre><code>myClass.addListener(new FancyInterfaceListener({
      void onListenerInterestingAction(Action a){
          ....interesting stuff here
      }
  });
  </code></pre>
  
  <p>So for example to handle an UIActionSheet call I have to declare another method in the same class, which seems a bit silly if I want to pass it data, because I'd have to store that data as a global variable. Here's an example of deleting something with a confirmation dialog asking you if your sure:</p>
  
  <pre><code>-(void)deleteItem:(int)indexToDelete{
      UIActionSheet *confirm = [[UIActionSheet alloc] initWithTitle:@"Delete Item?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:nil];
      [confirm showInView:self.view];
      [confirm release];
  }
  </code></pre>
  
  <p>and the UIActionSheetDelegate in the same class:</p>
  
  <pre><code>- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
      if (buttonIndex == 0){
          [[Settings sharedSettings] removeItemAtIndex:/*need index variable here*/];
          [drinksTable reloadData];
      }
  }
  </code></pre>
  
  <p>What I want to be able to do is declare it inline, just like I did in the java example at the top. Is this possible?</p>