title: How to Get Current First Responder from Window Controller in Cocoa?
body: <p>I would like to find the first responder view in a window. To do this, I would like to implement a category like this:</p>
  
  <pre><code>    @implementation  NSView (ViewExtensions)
  - (NSView *)findFirstResponder
  {
      if ([self isFirstResponder]) {        
          return self;     
      }
  
      for (NSView *subView in [self subviews]) {
          NSView *firstResponder = [subView findFirstResponder];
  
          if (firstResponder != nil) {
              return firstResponder;
          }
      }
  
      return nil;
  }
  
  @end
  </code></pre>
  
  <p>The above code is based on this question/answer on SO: <a href="https://stackoverflow.com/questions/1823317/how-do-i-legally-get-the-current-first-responder-on-the-screen-on-an-iphone">Get the current first responder without using a private API</a>.</p>
  
  <p>The problem, perhaps, is that NSResponder doesn't have an isFirstResponder method like UIResponder does. What is the equivalent for NSResponder?</p>
  
  <p>If the method above is implemented as above, I of course get the debug message: "'NSView' may not respond to 'isFirstResponder'".</p>
  
  <p>How do I make findFirstResponder work in Cocoa?</p>
  
  <p>Further information: I would later like to use the above method in my window controller in some way like:</p>
  
  <pre><code>        NSArray *copiedObjects;
          if ([[self window]contentView] == MyTableView) {
              copiedObjects = [tableController selectedObjects];
          }
          if ([[self window]contentView] == MyOutlineView) {
              copiedObjects = [treeController selectedFolders];
          }
  </code></pre>