discuss-gnustep
[Top][All Lists]
Advanced

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

Re: KVC


From: Helge Hess
Subject: Re: KVC
Date: Wed, 6 Jun 2007 10:37:03 +0200

On Jun 6, 2007, at 09:54, Richard Frith-Macdonald wrote:
Perhaps you are thinking of NSMutableDictionary? KVC is only for setting properties via appropriately named methods or direct access to instance variables.
Good point ... using non-ascii keys cannot ever work.

Why? As in the first sentence, NSMutableDictionary, is already an example which *always* works. So it does in WOComponent, EOGenericRecord, D2WContext, WOSession, WebScriptObject (WebKit access to JS objects, which have UTF-8 IDs!) etc etc etc

The root issue is this

  "KVC is only for setting properties via appropriately named methods"

which is wrong. KVC is for implementing object-level properties and how the property names are mapped to values is the task of the *object* which can choose to override the -valueForKey: method. In fact this is quite similiar to selector=>method mapping / distinction.


But of course you are right that the *default implementation* of - valueForKey: can never handle those keys. And the way to respond is calling -handleQueryForUnboundKey:, not an NSStringCharsetException.


However, we should try to make sure that the mode of failure matches that of the MacOS-X implementation ... what does MacOS-X do when it is given an unusable key? Since Helge raised this issue, my guess is that MacOS-X fails quietly in some way rather than raising an exception.

No, it does the right thing. Since an object which doesn't override KVC methods can't handle the key, it invokes -handleQueryForUnboundKey:.

Changing the code to use UTF-8 as he suggests might be the best way to mimic MacOS-X behavior.

Interestingly the documentation on KVC says:
"A key is a string that identifies a specific property of an object. Typically, a key corresponds to the name of an accessor method or instance variable in the receiving object. Keys must use ASCII encoding, begin with a lowercase
   letter, and may not contain whitespace."

Which reflects the current gnustep-base implementation, but not the Real World (tm) and common practice ;-) I consider this a documentation bug, though maybe they consider calling -handleQueryForUnboundKey: an error.

BTW: does Objective-C 2.0 allow UTF-8 method names? Java added this.

Anyway, the first step is to write some testcases for using the various KVC methods with non-ascii keys and run them on MacOS-X to see how they 'should' perform. After that you may want to modify GNUstep-base to match where necessary.

That makes sense. One important thing to keep in mind here is that there is NSCFDictionary on MacOS. (which affects mutability behaviour pretty badly, also in KVC set situations)

Greets,
  Helge
--
Helge Hess
http://www.helgehess.eu/






reply via email to

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