bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix, Base, NSKeyValueCoding (SetValueForKey())


From: David Ayers
Subject: Re: Fix, Base, NSKeyValueCoding (SetValueForKey())
Date: Tue, 23 Jun 2009 08:04:32 +0200

Am Dienstag, den 23.06.2009, 11:54 +0800 schrieb Georg Fleischmann:
     I. Hi,
> 
> here is a fix for NSKeyValueCoding SetValueForKey() to prefer the key  
> as is (without leading underscore) before trying with underscore (_key).
> 
> My problem: When loading a Nib file with a key named "infoPanel" for  
> NSApplication, the value gets set to "_infoPanel" instead, which also  
> exists in GNUstep.

I don't have current Cocoa, but the preference to use _infoPanel before
infoPanel is documented KVC behavior.  I would suppose the "bug" would
be the fact that NSApplication has an ivar named "_infoPanel" if such an
ivar does not exist Cocoa.

Cheers,
David

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/KeyValueCoding/Concepts/SearchImplementation.html
Default Search Pattern for setValue:forKey:
When the default implementation of setValue:forKey: is invoked for a
property the following search pattern is used:

     1. The receiver’s class is searched for an accessor method whose
        name matches the pattern -set<Key>:. 
        
     2. If no accessor is found, and the receiver’s class method
        accessInstanceVariablesDirectly returns YES, the receiver is
        searched for an instance variable whose name matches the pattern
        _<key>, _is<Key>, <key>, or is<Key>, in that order.
        
     3. If a matching accessor or instance variable is located, it is
        used to set the value. If necessary, the value is extracted from
        the object as described in “Representing Data as Objects.”
        
     4. If no appropriate accessor or instance variable is found,
        setValue:forUndefinedKey: is invoked for the receiver.
        

> 
> *** Source/NSKeyValueCoding.m.old     2009-02-28 14:31:08.000000000 +0800
> --- Source/NSKeyValueCoding.m 2009-06-23 11:28:56.000000000 +0800
> ***************
> *** 116,143 ****
>             if ([[self class] accessInstanceVariablesDirectly] == YES)
>               {
>                 buf[size+4] = '\0';
> -               buf[3] = '_';
>                 buf[4] = lo;
> !               name = &buf[3];       // _key
>                 if (GSObjCFindVariable(self, name, &type, &size, &off) == NO)
>                   {
>                     buf[4] = hi;
>                     buf[3] = 's';
>                     buf[2] = 'i';
> !                   buf[1] = '_';
> !                   name = &buf[1];   // _isKey
>                     if (GSObjCFindVariable(self,
>                       name, &type, &size, &off) == NO)
>                       {
>                         buf[4] = lo;
> !                       name = &buf[4];       // key
>                         if (GSObjCFindVariable(self,
>                           name, &type, &size, &off) == NO)
>                           {
>                             buf[4] = hi;
>                             buf[3] = 's';
>                             buf[2] = 'i';
> !                           name = &buf[2];   // isKey
>                             GSObjCFindVariable(self,
>                               name, &type, &size, &off);
>                           }
> --- 116,143 ----
>             if ([[self class] accessInstanceVariablesDirectly] == YES)
>               {
>                 buf[size+4] = '\0';
>                 buf[4] = lo;
> !               name = &buf[4];       // key
>                 if (GSObjCFindVariable(self, name, &type, &size, &off) == NO)
>                   {
>                     buf[4] = hi;
>                     buf[3] = 's';
>                     buf[2] = 'i';
> !                   name = &buf[2];   // isKey
>                     if (GSObjCFindVariable(self,
>                       name, &type, &size, &off) == NO)
>                       {
> +                       buf[3] = '_';
>                         buf[4] = lo;
> !                       name = &buf[3];       // _key
>                         if (GSObjCFindVariable(self,
>                           name, &type, &size, &off) == NO)
>                           {
>                             buf[4] = hi;
>                             buf[3] = 's';
>                             buf[2] = 'i';
> !                           buf[1] = '_';
> !                           name = &buf[1];   // _isKey
>                             GSObjCFindVariable(self,
>                               name, &type, &size, &off);
>                           }
> 
> 
> 
> _______________________________________________
> Bug-gnustep mailing list
> Bug-gnustep@gnu.org
> http://lists.gnu.org/mailman/listinfo/bug-gnustep
-- 
David Ayers          Fellow of the Free Software Foundation Europe
http://www.fsfe.org                     http://fellowship.fsfe.org






reply via email to

[Prev in Thread] Current Thread [Next in Thread]