• 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: Calculated Field examples for Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculated Field examples for Core Data


  • Subject: Re: Calculated Field examples for Core Data
  • From: Clayton Leitch <email@hidden>
  • Date: Sun, 14 Aug 2005 11:41:10 -0400

Thank You, I missed the typo. Everything now works as expected. Now I have to move on to find a way to get the totals for all the records, namely add all the period costs up. I believe a fetch construct will be the best way to do this.
On Aug 14, 2005, at 11:08 AM, mmalcolm crawford wrote:



On Aug 14, 2005, at 7:41 AM, Clayton Leitch wrote:


Well, I found a document that talked about derived in core data, NSPersistentDocumentTutorial.pdf.


That's the article at <http://developer.apple.com/documentation/ Cocoa/Conceptual/NSPersistentDocumentTutorial/03_CustomClass/ chapter_4_section_3.html>...



When I compiled the file I received the errors that are described below:
<Picture 1.png>
If I uncomment the self setKeys lines I get a selector unrecognized error when I try to run the project.



The method is 'setKeys:triggerChangeNotificationsForDependentKey:' (note "Dependent").
You should also only specify those attributes upon which the dependent key is dependent (for example, it appears that 'differenceCurrentPeriod' is only dependent upon 'actual...' and 'predictedPeriodCost' (in your code both calculated keys are dependent upon all four attributes).



I have tried various means to do the subtraction including the decimalNumberBySubtracting method. All either give me an error or a warning. I also tried primitiveValueForKey with no success.



You cannot do arithmetic calculations with NSNumbers with the pointer values.


What did you try?  How are the attributes defined in the model?

Did you try anything simple like

- (NSDecimalNumber *)differenceCurrentPeriod
{
float periodPredicted = [[self valueForKey:@"predictedPeriodCost] floatValue] -
[[self valueForKey:@"actualPeriodCost] floatValue];


    return [NSDecimalNumber numberWithFloat:periodPredicted];
}

or better:

- (NSDecimalNumber *)differenceCurrentPeriod
{
return [[self valueForKey:@"predictedPeriodCost] decimalNumberBySubtracting:
[self valueForKey:@"actualPeriodCost]];
}


?

mmalc

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


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Calculated Field examples for Core Data (From: Clayton Leitch <email@hidden>)
 >Re: Calculated Field examples for Core Data (From: mmalcolm crawford <email@hidden>)
 >Re: Calculated Field examples for Core Data (From: Clayton Leitch <email@hidden>)
 >Re: Calculated Field examples for Core Data (From: mmalcolm crawford <email@hidden>)
 >Re: Calculated Field examples for Core Data (From: Clayton Leitch <email@hidden>)
 >Re: Calculated Field examples for Core Data (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: What's wrong with having multiple windows per document in only one nib?
  • Next by Date: Re: Sync services notification
  • Previous by thread: Re: Calculated Field examples for Core Data
  • Next by thread: Copy managed object between contexts?
  • Index(es):
    • Date
    • Thread