title: Multiple filtered lists per NSArrayController
body: <p>What I need to do is simple, Say I have a list of student domain objects</p>
  
  <pre><code>@implementation Student : CPObject
  {
      CPString name @accessors;
      BOOL isLate @accessors;
      BOOL isMale @accessors:
  }
  </code></pre>
  
  <p>I have a list of these <code>Student</code> objects stored in an <code>NSMutableArray</code> which is a part of my model object. </p>
  
  <p>I have a <code>NSTableView</code> showing these <code>Student</code> objects, the table has check boxes to edit the <code>isLate</code> and <code>isMale</code> attribute. The table is backed by an <code>NSArrayController</code> which proxys the <code>NSMutableArray</code> from the model.</p>
  
  <p>Else where in the interface, I want to have 2 textfields displaying the "number of late students" and "number of male students" and thats where my problem comes in.</p>
  
  <p>Since <code>NSArrayController</code> supports filtering via predicate, my initial thought was to create 3 <code>NSArrayController</code> objects, one for proxying the tableview, on for each aggregate display (number of late students, number of male students). For the aggregate controllers, I would apply filtering and bind the text fields to the <code>arrangedObjects.@count</code>. However this seems like the wrong approach since the main controller making edits to the <code>NSMutableArray</code> would have no way of informing the changes made to the 2 other controllers.</p>
  
  <p>Another approach I thought about was mentioned here. <a href="http://cocoa-nut.de/?tag=nsarraycontroller" rel="nofollow noreferrer">http://cocoa-nut.de/?tag=nsarraycontroller</a>. Using this approach, I would binding the 2 "slave" <code>NSArrayController</code> performing the aggregate operations on the "master" controller which backs the tableview. However this approach doesn't seem that clean either. </p>
  
  <p>Thirdly, I read this post here: <a href="https://stackoverflow.com/questions/3113974/singleton-nsmutablearray-accessed-by-nsarraycontroller-in-multiple-nibs">Singleton NSMutableArray accessed by NSArrayController in multiple NIB&#39;s</a> . This tends to suggest that I should move the complexity into my model object instead. Perhaps I should create a <code>StudentList</code> class with <code>allStudents</code>, <code>maleStudents</code>, <code>lateStudents</code> attributes for binding? This seems overkill for something so simple.</p>
  
  <p>Overall, this seems like a pretty common and simple operation to have in a program but I'm relatively new to Cocoa so I am really not sure what is the "right" way to do it. Please enlighten me. </p>