如何从数组中删除对象,该数组包含字典

时间:2015-10-07 11:14:00

标签: ios

我将数据存储在数组中......

while ([delegate_obj.Recordsetmaster next])
    {
    NSMutableDictionary *local_DICT = [NSMutableDictionary new];

    NSString *str_id = [delegate_obj.Recordsetmaster stringForColumn:@"category_id"];
    [local_DICT setObject:str_id forKey:@"category_id"];

    NSString *str_name = [delegate_obj.Recordsetmaster stringForColumn:@"category_name"];
    [local_DICT setObject:str_name forKey:@"category_name"];

    NSString *str_status = [delegate_obj.Recordsetmaster stringForColumn:@"status"];
    [local_DICT setObject:str_status forKey:@"status"];

    NSString *str_image = [delegate_obj.Recordsetmaster stringForColumn:@"image"];
    [local_DICT setObject:str_image forKey:@"image"];

    [category_array addObject:local_DICT];
    }

现在我想从数组中删除第5个索引值怎么做?

1 个答案:

答案 0 :(得分:1)

我认为它只是[NSMutableArray removeObjectAtIndex:],但我还希望提供更直接的代码实现:

NSDictionary *keys = @{ @"category_id", @"category_name", @"status", @"image" };
while ([delegate_obj.Recordsetmaster next])
{
    NSMutableDictionary *local_DICT = [NSMutableDictionary new];
    for (NSString *key in keys) {
        id value = [delegate_obj.Recordsetmaster stringForColumn:key];
        NSAssert(value, @"No value for '%@'", key);
        [local_DICT setObject:id forKey:key];
    }
    [category_array addObject:local_DICT];
}