coredata - fetch one attribute into an array

前端 未结 2 1108
时光取名叫无心
时光取名叫无心 2021-01-02 03:14

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

Example

2条回答
  •  再見小時候
    2021-01-02 04:02

    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"];
    

提交回复
热议问题