RE: KVC pitfall (was: validation)
RE: KVC pitfall (was: validation)
- Subject: RE: KVC pitfall (was: validation)
- From: "Pierre Bernard" <email@hidden>
- Date: Wed, 21 Jan 2004 09:13:09 +0100
- Thread-topic: KVC pitfall (was: validation)
Hi!
The is<Key> method is for boolean values. I happen to use it quite often: isActive(), isObsolete(),...
I took the habit to use has<Key> for methods that check if a given variable is set: hasFirstName(),...
public boolean hasSomeKey()
{
return someKey != null;
}
Pierre
-----Original Message-----
From: Alexander Spohr [mailto:email@hidden]
Sent: Wednesday, January 21, 2004 8:54 AM
To: WebObjects apple
Subject: KVC pitfall (was: validation)
ho ho ho,
Am 20.01.2004 um 20:01 schrieb Geoff Hopson:
> It's a kinda sorta coding style, I guess. The key value coding stuff
> looks for a method called someKey(), getSomeKey(), then an attribute
> _someKey and probably one or two more combos.
yep, here's the pit:
NSKeyValueCoding checks FIRST for isSomeKey() before trying someKey
{the ivar}.
i think that's a bad idea!
example binding is
someRep: WORepetition {
list = someList;
item = someKey;
}
example code is
public String someKey; // as an iterator maybe
public boolean isSomeKey()
{
return someKey != null;
}
// as i am lazy i do not implement someKey() for an iterator ivar here
guess what happens? we ran into that pit more than once. took us a
while to find it in the first place. if you see it the second time you
know what it is. but it is anoying that you can not name your
methods/ivars as you like, because KVC is running through 10000
different checks to get that value.
http://developer.apple.com/documentation/WebObjects/Reference/API/com/
webobjects/foundation/NSKeyValueCoding.html
"For the key "lastName", this would be _lastName, _isLastName,
lastName, or isLastName"
i don't understand the is<key> here. if i bind something to lastName i
am surely talking about "Spohr", "Hopson" or "da Vinci". would anyone
bind "van Gogh" to isLastName? i would bind something like
boolean isLastName()
{
return anArrayOfLastNames.containsObject(lastName)
}
to it.
> As a side note, anyone know how to get Eclipse to auto-generate method > names like the above, instead of set_myString and get_myString? Does
> that 'Accessor' service on MacOSX work with Java and Eclipse?
i just implemented a quick hack to parse objc. but it might be easy to
convert that to java. did not try yet.
eclipse seems to show the services menu but everything is disabled in
there.
atze
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.