Loop through NSDictionary to create separate NSArrays

后端 未结 3 436
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 18:20

I have a large NSDictionary that I need to loop through and create separate NSArrays. Here are the contents:

(
        {
        id =          


        
3条回答
  •  时光取名叫无心
    2021-02-05 18:53

    Modern Objective-C syntax:

    NSMutableArray *things = [NSMutableArray array];
    NSMutableArray *stuff = [NSMutableArray array];
    NSMutableArray *bits = [NSMutableArray array];
    
    [dictionaries enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        [things addObject:[obj valueForKeyPath:@"thing"]];
        [stuff addObject:[obj valueForKeyPath:@"enclosing_object.stuff"]];
        [bits addObject:[obj valueForKeyPath:@"bits"]];
    }];
    

提交回复
热议问题