• 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: Proper place for functions in KVC paths?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper place for functions in KVC paths?


  • Subject: Re: Proper place for functions in KVC paths?
  • From: Lachlan Deck <email@hidden>
  • Date: Tue, 29 Aug 2006 11:47:31 +1000

Hi there,

On 26/08/2006, at 5:32 AM, Chuck Hill wrote:

On Aug 24, 2006, at 5:57 PM, Lachlan Deck wrote:
On 22/08/2006, at 2:53 AM, Chuck Hill wrote:
On Aug 21, 2006, at 7:59 AM, John Huss wrote:

It seems that key-value coding allows serveral different ways of using
functions (like @sum, @avg, etc) in key paths that all seem to work.
Like,


@sum.array.key.path
email@hidden
array.key.path.@sum

Is there a proper way to write these?

I am surprised that these all work. The NSArray documentation implies :-) the that intended use is


<keyPath to array>@<operator>.<keyPath to value>

I think the api implies they all work and will have differing outcomes depending on what you would like to 'sum' or 'count' etc. e.g., Consider the keypath: 'company.people.accounts.totalLiability'.


If I want to know how much is owed in total:
Number total = ( Number )company.valueForKeyPath ( "@sum.people.accounts.totalLiability" );

I am curious if you have actually used this?

Obviously not enough! Bummer...

I meant company.valueForKeyPath ( "email@hiddenLiability" ) - but that's still wrong. You can only provide toOne keyPaths after @sum it seems (i.e., "email@hiddenLiability" ) which will succeed (having now tested).

These operators are for NSArray (out of the box, sans Wonder) and it appears that company is an EO, not an NSArray. Thus, I would expect the above statement to produce a runtime error with an unknown key of @sum.

Correct.

If I would like to know how much each person owes:
NSArray totals = ( NSArray )group.valueForKeyPath ( "email@hiddenLiability" );

I am also unclear on how that would evaluate. people.valueForKeyPath ("accounts.totalLiability") should, I think, produce an array of arrays. Is @sum able to handle that correctly?

Unfortunately not. I spoke presumptuously and in haste...sorry about that. It seems to me, however, that this would be the desired behaviour. i.e., for the resulting array to contain the elements that are the sum of the inner arrays.


with regards,
--

Lachlan Deck



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Proper place for functions in KVC paths?
      • From: John Larson <email@hidden>
References: 
 >Proper place for functions in KVC paths? (From: "John Huss" <email@hidden>)
 >Re: Proper place for functions in KVC paths? (From: Chuck Hill <email@hidden>)
 >Re: Proper place for functions in KVC paths? (From: Lachlan Deck <email@hidden>)
 >Re: Proper place for functions in KVC paths? (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: Looks like ThinkSecret got some of the scoop on WO from WWDC'06
  • Next by Date: Re: Looks like ThinkSecret got some of the scoop on WO from WWDC'06
  • Previous by thread: Re: Proper place for functions in KVC paths?
  • Next by thread: Re: Proper place for functions in KVC paths?
  • Index(es):
    • Date
    • Thread