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 18:10:22 +0000 (GMT)

>  >| I suggest that you do as follows in your custom subclass -
>  >| 
> [...]
>  >|   /* If there is an ivar, use it.  */
>  >| This should support all your needs - 
>  >| 
>  >|  ivars take precedence over everything else.
>  >|  dictionary values take precedence over getXXX.
>  >|  getXXX are still used when all else fails.
> 
> But getXXX should be called before ivar access (during the valueForKey 
> process). :-(

You can use storedValueForKey: which looks up ivars before set/get
methods.

So I suppose you could change as follows -

- (id) storedValueForKey: xxx
{
  if (ivar)
    {
      return [super storedValueForKey: xxx];
    }

  if (canFindInDictionary)
    {
      return valueFoundInDictionary;
    }

  return [super storedValueForKey: xxx];
}

- (id) valueForKey: xxx
{
  if (ivar)
    {
      /* Call storedValueForKey: as that looks up ivars first! */
      return [super storedValueForKey: xxx];
    }

  if (canFindInDictionary)
    {
      return valueFoundInDictionary;
    }

  /* Call super's implementation.  */
  return [super valueForKey: xxx];
}

Modulo all approximations and code to fill in, it might work. :-)




reply via email to

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