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 9089007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:02:23+00:00 2026-06-16T22:02:23+00:00

Aim: I would like to fetch the value of one attribute (from an entity)

  • 0

Aim: I would like to fetch the value of one attribute (from an entity) from the database (core data) into an array.

Example

Entity Name = Employees

Attribute = employeeID

I just want all the employeeIDs populated into an array / set.

Question

Given below is my implementation, I just feel it is kind of a round about way, I would like to know if there is a better way to do this.

Code

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Employees"];

fetchRequest.resultType = NSDictionaryResultType;

[fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:@"employeeID", nil]];

NSError *error      = nil;
NSArray *results    = [self.managedObjectContext executeFetchRequest:fetchRequest
                                                               error:&error];

NSMutableArray *employeeIDs = [NSMutableArray array];

for(id currentRecord in results)
{
    [employeeIDs addObject:[currentRecord objectForKey:@"employeeID"]];
}
  • 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-16T22:02:24+00:00Added an answer on June 16, 2026 at 10:02 pm

    You can avoid the last for loop,

    Instead of,

    NSMutableArray *employeeIDs = [NSMutableArray array];
    
    for(id currentRecord in results)
    {
        [employeeIDs addObject:[currentRecord objectForKey:@"employeeID"]];
    }
    

    Try this,

    NSMutableArray *employeeIDs = [results valueForKey:@"employeeID"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The aim: I would like a Tumblr blog to pull CSS from a Rails
The aim I would like to set such size for the DataGrid (standard, from
AIM: I would like to tail the last line of the file.txt and input
AIM: I would like to set the below function to call every 5 seconds.
Is it possible to create types like e.g. String(20) in scala? The aim would
I would like to test a function with a tuple from a set of
I would like to run a query from a table where the content is
We have been manually been keying Amazon orders into our system and would like
I would like to add a random value to a table. While I know
Well to begin i would like to mention that the aim of this question

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.