Return NSArray from NSDictionary

后端 未结 3 1473
太阳男子
太阳男子 2021-01-21 17:58

I have a fetch that returns an array with dictionary in it of an attribute of a core data object.

Here is my previous question: Create Array From Attribute of NSObject F

3条回答
  •  灰色年华
    2021-01-21 18:12

    The Fast Enumeration method:

    NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:array.count];
    for (NSDictionary *d in objects) {
      [data addObject:[d objectForKey:@"timeStamp"]];
    }
    

    The Block enumerator method:

    NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:array.count];
    [objects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
      [data addObject:[obj objectForKey:@"timeStamp"]];
    }];
    

    Either way, 'data' contains just an array of NSDate instances.

提交回复
热议问题