• 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
Trying to calculate a running total using Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trying to calculate a running total using Core Data


  • Subject: Trying to calculate a running total using Core Data
  • From: Felix Rodriguez <email@hidden>
  • Date: Mon, 21 Apr 2008 04:06:39 -0400

I am trying to figure out how to calculate a running total using core data. I have created an entity called Transactions that have the following properties.

Transactions
	amount
	balance


I am trying to calculate the balance by adding up the amount of all the previous balances. I have subclased NSManagedObject and overridden awakeFromFetch. Here is the code I have so far.


- (void)awakeFromFetch
{
[super awakeFromFetch];

double amount = [[self valueForKey:@"amount"] doubleValue];
[self setValue:[NSNumber numberWithFloat:amount] forKey:@"balance"];
}


This routine only copies the amount to the balance property. I am thinking that I have to Query all of the previous transactions and calculate their totals. I know how to create a NSFetchRequest on a transaction object but I am unsure on how to create the NSPredicate object to extract all the transactions that were created prior to the current transaction. Thanks for any help you can provide.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Trying to calculate a running total using Core Data
      • From: Keary Suska <email@hidden>
    • Re: Trying to calculate a running total using Core Data
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: How to disable Energy Saving mode ?
  • Next by Date: Re: After Unarchive Object Exists, After First GUI Action, gone...
  • Previous by thread: Re: How to disable Energy Saving mode ?
  • Next by thread: Re: Trying to calculate a running total using Core Data
  • Index(es):
    • Date
    • Thread