title: IB NSController subclass bindings
body: <p>In Mac OS X have an object that's a subclass of <code>NSObject</code> in Interface Builder, i.e., I've added an <code>NSObject</code> instance and set its class to <code>JDMyClass</code> (which is itself an <code>NSController subclass</code>). In IB I've created some bindings from some interface elements using the values property in <code>JDMyClass</code>, e.g., a text view bound to <code>values.anyProperty</code>.</p>
  
  <p>According to <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW19" rel="nofollow">Nib Files documentation</a>:</p>
  
  <blockquote>
    <p>Custom objects other than those described in the preceding steps receive an <code>init</code> message.</p>
  </blockquote>
  
  <p>This means I don't ever have the opportunity to use <code>initWithCoder:</code>, which is where the information for the bindings comes from (I think). (That same document indicates which objects <em>do</em> receive <code>initWithCoder:</code> instead of <code>init</code>.</p>
  
  <p>Later the same documentation indicates:</p>
  
  <blockquote>
    <ul>
    <li>Bindings<br>
    <ul>
    <li>In OS X, Cocoa uses the <code>bind:toObject:withKeyPath:options:</code> method of the source object to create the connection between it and its target object.</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>I was dubious but added it to my <code>JDMyClass</code> anyway, and the breakpoint is never hit, so Mac OS X isn't trying to re-establish any bindings from IB.</p>
  
  <p>While I could make my <code>JDMyClass</code> a subclass of, e.g., <code>NSUserDefaultsController</code>, and set the <strong>Shared User Defaults Controller</strong> IB instance to my class, I don't really want to do this. It <em>works</em>, i.e., I get to <code>initWithCoder:</code>, call <code>super</code> and have all my bindings set, but it seems like a kludge.</p>
  
  <p>The bindings aren't necessarily known ahead of time, and so I cannot establish them in code.</p>
  
  <p><strong>So, how do I get the bindings set in Interface Builder to apply to my custom class when it's loaded from the Nib, when I have no idea in advance what the bindings are?</strong></p>
  
  <p>Thanks!</p>