title: Dynamic population of a NSTableView with NSDictionaries with unknown keys
body: <p>Is there no "simple" way to bind an NSArray that contains NSDictionaries with unknown keys to a NSTableView?</p>
  
  <p>What is the best approach to solve this "common" problem?</p>
  
  <p>Coming from c#/asp.net it seems to be a really painful operation.</p>
  
  <p>edit:</p>
  
  <p>To clarify what the app is about: its a simple queryeditor that displays the result of the query in a tableview.</p>
  
  <p>I have tried to follow this example: <a href="http://www.cocoabuilder.com/archive/cocoa/150245-dynamic-columns-in-nstableview.html" rel="nofollow">http://www.cocoabuilder.com/archive/cocoa/150245-dynamic-columns-in-nstableview.html</a></p>
  
  <p>I use an object that implements the NSTableViewDataSource protocol.</p>
  
  <p>When the user issues the first query, the result is displayed correctly. But the second query shows something strange: the columns are not removed correctly and are added to the existing ones, but not all.</p>
  
  <p>In the method, that builds the table i use something like this:</p>
  
  <pre><code>    NSArray *columns = [_resultTableView tableColumns];
  
      if(columns &amp;&amp; [columns count] &gt; 0)
      {
          for( int i=0; i &lt; [columns count]; i++)
          {
              NSTableColumn *col = [columns objectAtIndex:i];
              NSLog(@"removing column: %@", [col identifier]);
              [_resultTableView removeTableColumn:col];
          }
      }
  
  
      NSDictionary *dict = [_resultTableDataSource.data objectAtIndex:0];
  
      NSArray *keys = [[dict keyEnumerator] allObjects];
  
      for( int i=0; i &lt; [keys count]; i++)
      {
          NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[keys objectAtIndex:i]];
          [column setEditable:NO];
          [[column headerCell] setStringValue:[keys objectAtIndex:i]];
          [_resultTableView addTableColumn:column];
      }
  
      [_resultTableView setDataSource:_resultTableDataSource];
  
      [_resultTableView reloadData];
  </code></pre>
  
  <p>_resultTableDataSource.data is a NSMutableArray with NSMutableDictionary's as records.</p>