Search code examples
cocoasubclasscocoa-bindingsnsarraycontroller

What are the reasons for subclassing NSArrayController?


I am trying to improve my KVC/KVO/Cocoa-Bindings-fu and was wondering what could be the reasons to subclass the NSArrayController?


Solution

  • I have a custom NSArrayController subclass that perform a whole bunch of task. I chose to implement these things there because I can then enjoy the full comfort of bindings and stuff. Here's what I use this now for:

    • Sometimes some items must be hidden and some must be shown
    • I perform custom sorting (i.e. grouping) in the controller
    • It is fed by the items of a different kind than it returns (get items, returns item nodes - dummy objects that forward most stuff)
    • I also use it to hold the filter criteria and search options currently on display
    • In addition, I added NSTableView delegate and data source support that allows drag & drop implementation right in the controller
    • I also customize tool tips for the cell in there

    Yeah, and so on. Basically this all boils down to this essence: subclass NSArrayController if you want different data out than you put in

    Max