coredata - fetch one attribute into an array

前端 未结 2 1107
时光取名叫无心
时光取名叫无心 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:00

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

提交回复
热议问题