Aim: I would like to fetch the value of one attribute (from an entity) from the database (core data) into an array.
Example
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"];
One way of doing it is-
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Employees"];
fetchRequest.resultType = NSDictionaryResultType;
NSError *error = nil;
NSArray *results = [self.managedObjectContext executeFetchRequest:fetchRequest
error:&error];
NSMutableArray *employeeIDs = [results valueForKey:@"employeeID"];