• 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: John Larson <email@hidden>
  • Date: Tue, 29 Aug 2006 16:43:59 -0500

I don't know about the others, but I know that @max and @min work on NSTimestamps too.

Also, I should have said that the recursion works like normal recursion: toward the end of the keypath until it hits the end of the keypath, then back out to the front of the keypath. Specifically, for valueForKeyPath("A.B.C") it calls valueForKey("A").valueForKeyPath ("B.C"). valueForKeyPath("B.C") calls valueForKey ("B").valueForKeyPath("C") which turns into valueForKey("C") at C.

source.valueForKeyPath("email@hiddenield") works by putting a conditional in NSArray's implementation of valueForKeyPath.
source.valueForKey("people").valueForKeyPath("@sum.somefield")
valueforKey("people") returns a plain old NSArray full of people
the source object calls valueForKeyPath("@sum.somefield") on that array
NSArray takes the next token which is "@sum". It sees it a special operator, takes it out of the keypath, and calls valueForKeyPath ("somefield") on each element in the array, then accumulates the total and returns it.
(if it was not an operator it would simply return an array composed of the results of valueForKeyPath("somefield") on each element in the array)


I probably got that wrong somewhere :-)

John
	

On Aug 29, 2006, at 4:20 PM, John Larson wrote:

Hello,


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


You can think of the keypath as a tokenized string that is evaluated recursively through the elements toward the end of the string and the @operators are looking for scalar values to iterate over and accumulate. So, for company.people.account.totalLiability where people is the only array, then email@hiddenLiability would produce the sum as desired. Suppose, however, that each person had multiple accounts. The following would also be valid: email@hiddenemail@hiddenLiability.


The point of this was to not leave the thread with the idea that there can only be one @operator in a keypath.

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


This email sent to email@hidden

_______________________________________________ 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
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>)
 >Re: Proper place for functions in KVC paths? (From: Lachlan Deck <email@hidden>)
 >Re: Proper place for functions in KVC paths? (From: John Larson <email@hidden>)

  • Prev by Date: Re: Proper place for functions in KVC paths?
  • Next by Date: Re: Subclass final class (Boolean) ?
  • 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