Re: Trying to calculate a running total using Core Data
Re: Trying to calculate a running total using Core Data
- Subject: Re: Trying to calculate a running total using Core Data
- From: Keary Suska <email@hidden>
- Date: Mon, 21 Apr 2008 09:33:04 -0600
- Thread-topic: Trying to calculate a running total using Core Data
on 4/21/08 2:06 AM, email@hidden purportedly said:
> 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
>
> <snip>
>
> 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.
First issue I see is how you can know what transaction objects "occur" prior
to any given object. I don't think you can rely on objects being retrieved
in any specific order that your data model doesn't enforce.
Next, AFAIK, there is no way to do what you want purely from an entity's
perspective--i.e. through a predicate or any instance method of the entity
class--unless you can rely that -awakeFromFetch is called in a predictable
order (which I can't answer), and you are willing to recalculate the entire
data set every time any change is made.
Otherwise, an outside "controller" object, perhaps who can watch for certain
changes or gets called at certain strategic times, will perform
re/calculations when needed.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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