• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: KVC pitfall (was: validation)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVC pitfall (was: validation)


  • Subject: Re: KVC pitfall (was: validation)
  • From: Alexander Spohr <email@hidden>
  • Date: Wed, 21 Jan 2004 11:50:33 +0100

pierre,

i know what the isKey is for :)

here's a better example of the pit in a component:

public class InstanceInfo extends WOComponent
{
  public SOLSurfaceInstance unit;         // a rep-item
  public SOLSurfaceInstance selectedUnit; // the users selection

  public boolean isSelectedUnit()         // the check (pitfall!)
  {
    return unit == selectedUnit;
  }
}

this will give you an exception if you try something like this in the wod:

containedUnit: InstanceInfo {
	selectedUnit = selectedUnit;
}

the KVC will call isSelectedUnit and stuff the resulting boolean into the selectedUnit ivar of the subcomponent (recursive InstanceInfo). is _should_ get the content of the selectedUnit ivar instead.
the fix is easy. i renamed the method to isUnitSelectedUnit(). but i don't think that should be the way to do it.


back to your example:
as you can see i use "isSomething" methods as well. but i would never hook such a method to the (imho crippled) key "something".


if i have
boolean isSomething { return aVal != 0 };

this wod looks wrong to me:
containerCanRepair: WOConditional {
	condition = something;
}

this is what i'd do:
containerCanRepair: WOConditional {
	condition = isSomething;
}

is there anyone out there who calls the isKey() methods by asking for "key" only?

	atze


Am 21.01.2004 um 09:13 schrieb Pierre Bernard:

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.
_______________________________________________
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.

References: 
 >RE: KVC pitfall (was: validation) (From: "Pierre Bernard" <email@hidden>)

  • Prev by Date: RE: KVC pitfall (was: validation)
  • Next by Date: Re: WO Newsgroup
  • Previous by thread: RE: KVC pitfall (was: validation)
  • Next by thread: Re(2): SSI within main.html
  • Index(es):
    • Date
    • Thread