I have an array with data from server. I can't change the server's response.
{
maximum = 30;
minimum = 1;
name = "Layer 1";
},
{
maximum = 60;
minimum = 45;
name = "Layer 1";
},
{
maximum = 60;
minimum = 45;
name = "Layer 2";
}
I have 3 objects in this array. 2 of them are with the same name but with different minimum and maximum values. I want to create an array which won't have duplications, so for example I'll have 2 object in my array, "Layer 1", "Layer 2". Layer 1 will have the 2 minimum values, and maximum values.
How it should look like:
{
name = "Layer 1"; value = [{maximum = 30;
minimum = 1},{ maximum = 60;
minimum = 45}];
},
{
maximum = 60;
minimum = 45;
name = "Layer 2";
}
I have tried to check if the "name" of the object at index "i" is equals to the "name" of the object at index "i+1" but it crahses, it says "beyond bounds (2):
rows = [mivne_shichva count];
NSMutableArray *layers = [[NSMutableArray alloc]init];
NSMutableDictionary *layer = [[NSMutableDictionary alloc]init];
for (int i = 0; i<rows; i++) {
if ([[[mivne_shichva objectAtIndex:i]valueForKey:@"name"] isEqualToString:[[mivne_shichva objectAtIndex:i+1]valueForKey:@"name"]]) {
NSLog(@"name equals to name in i+1");
}
[layer setValue:[[mivne_shichva objectAtIndex:i]valueForKey:@"name"] forKey:@"name"];
[layer setValue:[[mivne_shichva objectAtIndex:i]valueForKey:@"minimum"] forKey:@"minimum"];
[layer setValue:[[mivne_shichva objectAtIndex:i]valueForKey:@"maximum"] forKey:@"maximum"];
[layers addObject:layer];
NSLog(@"layers :::: %@",layers);
}
rows - 1, not up torows, when you plan to usei + 1as an index expression.