Great stuff. Thanks a lot, that works a treat.

Feed: Cocoa mail archive
Posted on: Monday, 29 September 2008 8:22 PM
Author: Steven Hamilton
Subject: NSManagedObject custom class & for loop

> The problem is when the code hits the for (transaction in
> transactions) loop it dumps to GDB with an obj_msgsend error and I
> can't see why. Am I trying to do something that a custom class
> shouldn't be able to do? If I comment out the loop it runs fine.


In the first line of your loop you're sending the -amount message to the
entity, not the transaction object.
That line should probably read NSNumber *amount = [transaction amount]

A few other things though, with more than a few transactions this will be
really slow. You could request the sum of the transaction amounts directly
from CoreData and it could handle them much quicker. Something like
[account valueForKeyPath:@"[EMAIL PROTECTED]"] assuming you've set
up a "transactions" relationship. If you don't have a relationship you
could still perform your fetch and issue a similar message to the
transactions array you get here, [transactions
valueForKeyPath:@"@sum.amount"]

If, for some reason, you still need to iterate over all of the objects
individually, I'd recommend that you don't convert your final balance to
an NSNumber until you're finished with your loop.

Ashley Clark




________________________________
This e-mail is sent by Suncorp-Metway Limited ABN 66 010 831 722 or one of its 
related entities "Suncorp".
Suncorp may be contacted at Level 18, 36 Wickham Terrace, Brisbane or on 13 11 
55 or at suncorp.com.au.
The content of this e-mail is the view of the sender or stated author and does 
not necessarily reflect the view of Suncorp. The content, including 
attachments, is a confidential communication between Suncorp and the intended 
recipient. If you are not the intended recipient, any use, interference with, 
disclosure or copying of this e-mail, including attachments, is unauthorised 
and expressly prohibited. If you have received this e-mail in error please 
contact the sender immediately and delete the e-mail and any attachments from 
your system.
If this e-mail constitutes a commercial message of a type that you no longer 
wish to receive please reply to this e-mail by typing Unsubscribe in the 
subject line.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to