gnustep-dev
[Top][All Lists]
Advanced

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

Re: Re[6]: Recent key-value encoding changes to NSObject.


From: Nicola Pero
Subject: Re: Re[6]: Recent key-value encoding changes to NSObject.
Date: Mon, 11 Feb 2002 19:24:41 +0000 (GMT)

>  >| takeStoredValue:forKey: is implemented in terms of b and setB:, not vice
>  >| versa.  
>  >| 
>  >| Unless - ... - unless the Apple documentation is wrong, and when it says
>  >| that takeStoredValue:forKey: makes steps 2,3,1 and 4 - that might be
>  >| actually wrong, and it might make steps 2,3 and 4 - but not 1.  Then you
>  >| could define setA: in terms of takeStoredValue:forKey:, because
>  >| takeStoredValue:forKey: would simply not look for setA:.  This would make
>  >| a lot of sense, so if anyone has an apple system, could you please check
>  >| if takeStoredValue:forKey: does use set<Key>: (as opposed to _set<Key>:)
>  >| or not ?
> 
> AFAIK, it use set<Key> if this method exists.
> 
> Here is some pointer on the steps:
>         http://wodeveloper.com/omniLists/eof/2000/June/msg00087.html
>         http://wodeveloper.com/omniLists/eof/2000/October/msg00076.html

Ok - so I think you want the internal dictionary to be accessed exactly
after the ivars, both in valueForKey: and storedValueForKey:.  The
following code does that -

/* This makes sure valueForKey: accesses the dictionary after the
   ivars.  */
- (id) handleQueryWithUnboundKey: (NSString *)key
{
  if (isInDictionary)
   {
     return dictionaryValue;
   }
  else
   {
     return [super handleQueryWithUnboundKey: key];
   }
}

/* This makes sure storedValueForKey: accesses the dictionary after the
   ivars.  */
- (id) storedValueForKey: (NSString *)key
{
  if (ivar)
    {
      return [super storedValueForKey: key];
    } 

  if (inDictionary)
   {
      return dictionaryValue;
   }

 return [super storedValueForKey: key];
}

then,

- (id) lastName
{
  return [storedValueForKey: @"lastName"];
}

will work; all the normal sequence of valueForKey: and storedValueForKey:
are the usual ones, except that dictionary lookup is performed exactly
after normal variables lookup.  Even if ... reading the thread on the
mailing list, I'm not sure that valueForKey: accesses the internal
dictionary at all !  That would even be simpler - you just remove the
handleUnboundQueryWithKey:.

If this is not yet correct, please would you list exactly the algorithm
you want to be used in your custom valueForKey: and storedValueForKey:.




reply via email to

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