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

  • SEARCH
  • Home
  • 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 8880881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:14:29+00:00 2026-06-14T20:14:29+00:00

I have a NSSet (e.g. fruits) which consists of NSManagedObjects and is created by

  • 0

I have a NSSet (e.g. “fruits”) which consists of NSManagedObjects and is created by using the following filtering code:

NSSet *fruits = [self.allFruits filteredSetUsingPredicate:
                         [NSPredicate predicateWithFormat:@"quantity > 10"];

Each of the fruits has the following properties (attributes): name (e.g.: apple, orange, banana), color (red, yellow, green) and quantity (100, 20, 10).

What would be the most efficient way to create a NSDictionary out of this NSSet which contains the names of the fruits as the keys and the quantities as the objects (e.g. key:object: apple: 100 orange: 20)?

This is how this could be done using block enumeration:

__block NSMutableDictionary *fruitsAndColors = [NSMutableDictionary dictionary];

[fruits enumerateObjectsUsingBlock:^(id fruit, BOOL *stop) {
      [fruitsAndColors setObject:fruit.color forKey:fruit.name];
}];

Is there a more elegant way to accomplish the same?

Thank you!

  • 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-14T20:14:30+00:00Added an answer on June 14, 2026 at 8:14 pm

    Have you tried using a custom NSManagedObject subclass with a method that writes writes each object out to a dictionary with the keys and values that you want.

    Then you can enumerate your NSSet and call this method on each object to create a collection of dictionaries.

    I’m only giving you a general idea because you’ve asked a general question. If you try and write the code you can come back with any further problems that you face.

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

Sidebar

Related Questions

I have the following code: self.temporaryImageArray = [(NSSet *)[[array objectAtIndex:0] images] allObjects] Array holds
I have this bit of code: [self.vManager playersNearLocation:userLocation block:^(NSSet *players, NSError *error) { if(players
I have the following code in my app which I could just copy and
i have one code which moves the uiimage on touch-event it's like this: -(void)touchesBegan:(NSSet
I have the following code: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSUInteger touchCount =
I have the following task: I'm given an NSSet of objects each of which
I have this code: [scrollView setMinimumZoomScale:1.00]; [scrollView setMaximumZoomScale:2.00]; scrollView.delegate=self; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
I have the following piece of code that I'm expecting to run on a
I have this snippet of code from a class created by Erica Sadun, that
I have a method which returns an NSArray with points to be plotted. Following

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.