for example:
attr_accessor :billy # will create setter and getter for billy with
all the appropritate KVO methods

def updateMyValue(sender) #called from a button perhaps
        setBilly(4)
end

#or setValue:4 forKey:billy

[EMAIL PROTECTED] = 4 will not work, because it bypasses the accessor methods


So you don't need to override the accessors unless you are doing some
additional work.

If you do override the accessors then you will have to put the whole
willChangeValueForKey, and didChangeValueForKey  calls in your
overwritten method.
In your code below you do override the accessor, and therefore lose
the KVO.



This turned out to be the key. The way to make it work automatically is just to use attr_accessor, but "setX(value)" within the program to modify it (even though that method isn't one you wrote). I had tried .= and self.X =, neither of which work, but that one does.

It even works with the Matrix binding to selectedTags. I get the sense it may be trickier with something more complex or dynamic - which I may eventually want to do, but I'm happy with this for now.

The trickier one was actually the Booleans. When you bind to a Boolean variable, it's now being set in a non-Ruby way. What that means is:
something if X
no longer works the way you'd expect - this is always true.
Instead you need to do:
something if X == true

I know some people prefer the more explicit style anyways, and maybe that's one reason why. Or it could be considered a bug. As I understand it, the NS YES and NO are integer values which is sort of troublesome with the way Ruby treats 'false'.

Thanks,

Michael

_______________________________________________
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to