/dev/trouble
Eric Roller's Development Blog

If you ask me, this is a bug: binding "enabled" of an NSMenuItem to anything does not make any difference. It seems that the target of the menu item needs to tackle the issue in the conventional manner, i.e. through the method:

- (BOOL) validateMenuItem:(NSMenuItem*)item
{
    if (itemShouldBeEnabled)
        return YES;

    return NO;
}

The downside of this is that the target may need access to other objects that would have beeen simple to achieve through the binding mechanism, sigh.

In a custom NSArrayController, an action was only to be done when we had a selection. The initial attempt was along the lines of:

if ([self selection])
{
    // do something
}

That, however, does not work since even an empty selection returns a proxy object:

(gdb) print-object [self selection]
<_NSControllerObjectProxy: 0x5bfa60>
(gdb) print-object [[self selection] valueForKeyPath:@"db.name"]

So I checked the NSObjectController documentation and was reminded that a NSNoSelectionMarker can be returned by the function, making me think it that the if statement could be changed like this (NOT):

if ([self selection] != NSNoSelectionMarker)
{
    // DOES NOT WORK
}

However, this does not work (but checking the return value of valueForKeyPath: might).

The most elegant solution for an NSArrayController would be to ignore the selection and just to check the (first) selectionIndex like this:

if ([self selectionIndex] != NSNotFound)
{
    // do something
}