Adding categories: first try.


I’m trying to add new categories to the NSArrayController class: it can select the first and the last item. I did so:

I get no errors, but I would like to but this object in IB, using a blue cube and binding buttons to its “selectFirst” and “selectLast” methods.

But I’m a bit lost: which standard object to start with? A standard ArrayController? And then, which class name to choose to have the new methods listed?

Thanks for your help.

For categories you don’t have to do anything differently in IB.

That’s right. Having

The new methods appear in the binding window of the standard NSArrayController. Incredible. Once again it’s like magic. 10 more lines of IF-ed code gone – and it works.


You could probably use:

#import "NSArrayController+selectEnds.h"


Yes, of course, it was unclear from my post but I have a .h and a .m file.

Categories are really fun. As long as I don’t add instance variables/properties, I can obtain from a existing class just this “why didn’t they implement this method” extra work – and certainly reusable.

Thank you, Shane, your MyriadHelpers have inspired me! :slight_smile:

Of course if I wanted something more complicated, like, for example, a NSSegmentedControl made of individual buttons instead of segments, able to send n different actions, subclassing would be unavoidable.

What I miss for the moment is a custom cell capable of implementing a NSColorWell into a standard cell-based table view. Still searching to subclass NSControlCell and filling the log console with pages of errors. :wink:


A table view cell can also be a custom NSCell which can contain custom UI elements.
For an example have a look at

Thank you, Stefan, Volltreffer.

That’s the kind of thing I was looking for.