title: coredata - fetch one attribute into an array
body: <p><strong>Aim:</strong> I would like to fetch the value of one attribute (from an entity) from the database (core data) into an array.</p>
  
  <p><strong>Example</strong></p>
  
  <p>Entity Name = Employees</p>
  
  <p>Attribute   = employeeID</p>
  
  <p>I just want all the employeeIDs populated into an array / set.</p>
  
  <p><strong>Question</strong></p>
  
  <p>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.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><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:&amp;error];
  
  NSMutableArray *employeeIDs = [NSMutableArray array];
  
  for(id currentRecord in results)
  {
      [employeeIDs addObject:[currentRecord objectForKey:@"employeeID"]];
  }
  </code></pre>