Re: Web scripting key does not work [Resolved]

Christiaan Hofman <[email protected]> Fri, 22 Oct 2010 13:38:39 +0200
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Hurray, I finally figured out how I can really make this work.

The trick is to override -attributeKeys, returning the property names you want to expose. Then it will check those keys instead of the ivar names.

Still filed a documentation bug report, I had to go into the webkit source code to figure this out.

Christiaan

On Oct 21, 2010, at 17:31, aglee wrote:

> On Oct 21, 2010, at 06:11 AM, Christiaan Hofman <[email protected]> wrote:
>> 
>> On Oct 21, 2010, at 5:36, Andy Lee wrote:
>> > I noticed in the CallJS example there is a comment that says the getter and setter are not called. I was going to mention that in my testing they *were* called, at least judging by the NSLogs. But maybe I was misreading the logs, since you say scripting does indeed go through the ivars.
>> > 
>> > Anyway, glad you at least got to the bottom of it.
>> > 
>> > --Andy
>> 
>> That comment is definitely wrong, it does seem to go through valueForKey: and setValue:forKey:, the accessors are indeed used, also in the CallJS sample as you can see in the logs. Perhaps it was not in an earlier OS version, this sample seems to be somewhat older.
>  
> I see the example code is dated March 2007 [1].
> 
> I don't remember when key-value coding was introduced, but most of today's NSKeyValueCoding methods are documented as available since 10.3 [2], which was released months later, in October 2007 [3].  And of course @property was long after that.
> 
> Probably not worth the few minutes of research, but sometimes I get curious about these things.
> 
> --Andy
> 
> [1] <http://developer.apple.com/library/mac/#samplecode/CallJS/Introduction/Intro.html>
> [2] <http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html>
> [3] <http://en.wikipedia.org/wiki/Mac_OS_X_Panther>
>