Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:17:31+00:00 2026-06-01T14:17:31+00:00

I have a NSFetchRequest that is returning all my saved objects (call them Item

  • 0

I have a NSFetchRequest that is returning all my saved objects (call them Items) and storing them in an NSMutableArray. Each of these Items have a category, an amount, and some other properties. My goal is to check the category of each Item and store the sum of the amounts for objects of the same category. So if I had these Items:

  • Red; 10.00
  • Blue; 20.00
  • Green; 5.00
  • Red; 5.00
  • Green; 15.00

then I would have an array or other type of container than has:

  • Red; 15.00
  • Blue; 20.00
  • Green; 20.00

What would be the best way to organize the data in such a manner? I was going to create a object class (call it Totals) that just has the category and amount. As I traverse through the fetch results in a for-loop, add Items with the same category in a Totals object an store them in a NSMutableArray. The problem I ran into with that is that I’m not sure how to check if an array contains a Totals object with a specific property. Specifically, a category that already exists. So if ‘Red’ exists, add the amount to it, otherwise create a new Totals object with category ‘Red’ and a the first Item‘s amount. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:17:33+00:00Added an answer on June 1, 2026 at 2:17 pm

    To answer your question and to give you generic methods that can prove helpful in many situations, you can use the [myObject isKindOfClass:aClass] method, then the respondsToSelector: method of NSObject.

    If you know what are the kind of data you’re gonna get.. You can just instantiate an object Totals with Red = 0, Blue = 0, Green = 0, then add amounts accordingly.

    As an other option, you can take a look at Key-value coding : link here

    you can use the NSMutableDictionary class to achieve that. You will look in your total object (NSMutableDictionary) if key exists, if not, create it, if yes add value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these objects that are unique except for two columns once of which
This has been driving me nuts all day. I have a weird bug that
I have a set of objects and for each object in this set I
I have to create a NSFetchRequest for my iPhone App that returns the same
For example. if I have a chat app that uses objects like: ChatRoom and
I currently have Core Data successfully returning all of the results for a specific
I have 2 views that contain a UITableView each. They are both displayed at
I have a parent class that handles all the UITableview persistent data management and
Have a singleton class for BNRItemStore, but when I tried to call it, I
I have a core data application that uses an NSPredicate in one of its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.