[MacRuby-devel] NSArrayController

Brad Wilson brad at lucky-dip.net
Sun Oct 5 17:41:54 PDT 2008


On 26/09/2008, at 11:03 PM, Richard Kilmer wrote:

>
> On Sep 26, 2008, at 8:52 AM, Brad Wilson wrote:
>
>>
>> On 26/09/2008, at 10:32 PM, Richard Kilmer wrote:
>>
>>>
>>> On Sep 26, 2008, at 3:17 AM, Brad Wilson wrote:
>>>>>
>>>
>>> Brad,
>>>
>>> Try this:
>>>
>>> def initialize
>>> @employees = []
>>> end
>>>
>>> I found this in the Indexed Accessor Patters for To-Map Properties
>>> section of the KVC programming guide:
>>>
>>> http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/AccessorConventions.html#/
>>> /apple_ref/doc/uid/20002174-BAJEAIEE
>>
>>
>> Ok that makes sense. I'll try it out. Thanks!
>>
>> I don't entirely understand KVC yet, and from what I understood the
>> standard ruby attr_accessor would be enough to handle it. I'll try
>> adding the extra methods.
>
> I think it depends on the way in which the key is being accessed.
> Sounds like the key you are accessing is being accessed as a
> collection (thus the need for these methods).
>
> If it was a simple property:
>
> attr_accessor :employees
>
> Would have been sufficient
>
> -rich

I've spent some more time on this and it looks like I don't need those  
extra methods you mentioned (though it's good to know they exist  
because it sure helped with debugging.

I'm not sure why this is, but it seems like the initialize method  
isn't getting called for MyDocument ( which extends NSDocument). I've  
replaced that with the code below and it seems to work fine. Which is  
good (I guess).

def init
@employees = []
super
end


Anyway, thanks again for your help.


Brad



More information about the MacRuby-devel mailing list