discuss-gnustep
[Top][All Lists]
Advanced

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

Re: KVC


From: Chris Farber
Subject: Re: KVC
Date: Wed, 6 Jun 2007 15:06:31 -0400


On Jun 6, 2007, at 4:13 AM, Helge Hess wrote:

On Jun 6, 2007, at 24:14, Chris Farber wrote:
produces an exception because the ß can't be converted to ASCII. I recommend switching the conversion to UTF-8.
I don't believe this is an issue, as you cannot use unicode for variables or method names.

I'm talking about KVC, not methods and ivars. Key-Value Coding is defined in terms of

  - (id)valueForKey:(NSString *)_key
  - (void)setValue:(id)_value forKey:(NSString *)_key;

Given your argumentation I could not use @ or - in keys just because they are not allowed in vars/method-names.

No restrictions apply to the key. KVC is not just another way to access methods, its a concept on its own and in fact there are plenty of places where those methods are mapped to something which has nothing to do with methods. Eg one of the more complicated ones is D2WContext which maps keys to a rule system in Direct2Web.

Please remember that KVC is not just for accessing methods but for arbitary key/value combinations.
Perhaps you are thinking of NSMutableDictionary?

There are two parts to KVC: the informal protocol, and the implementation. I made the mistake of thinking you were talking about the implementation for two reasons. In your example, you used takeValue:forKey:; if you had overridden takeValue:forKey:, then it would not be our implementation at fault, and if you had not I could only assume that you were trying to set an ivar or call a method, neither of which can contain unicode. I also had not been thinking about key paths…


This is one of the simplest objects which modify the way KVC works. EOGenericRecord is another one and a good example where unicode plays a role (Given that eg PostgreSQL table, column names can be arbitary strings).

KVC is only for setting properties via appropriately named methods or direct access to instance variables.

Sorry??? Have you ever used WebObjects or EOF (or a clone of those)? :-) The power of KVC is that its separate. Eg it allows you to do trampolines like this:

  @implementation MyComponent
  - (id)labels {
    return self->labelHandler;
  }
  @end

  @implementation MyLabelHandler
  - (id)valueForKey:(NSString *)_key {
    return [[NSBundle bundle] labelForKey:_key];
  }
  @end

  LocalizableString.strings:
  WelcomeTitle = "Hello Friendly Visitor!!!";

And then in the WO template:
  <#WOString var:value="labels.WelcomeTitle" />



In this, WebObjects should be invoking valueForKeyPath:, and you are totally correct - we need to support unicode here as the objects along the path may or may not be using the default implementation of KVC. Thanks for pointing this out.

Chris


Anyways, to make a long story short: if you want to be compatible with Cocoa, you need to allow arbitary keys. This should hopefully stop further argumentation ;-)

Thanks,
  Helge

PS: its just a matter of time until UTF-8 is allowed in selectors. Java already does this (which BTW also affects KVC in combination with Java bridges ...)
--
Helge Hess
http://www.helgehess.eu/




_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep





reply via email to

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