Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:04:50+00:00 2026-06-16T02:04:50+00:00

I have an array with data from server. I can’t change the server’s response.

  • 0

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);            
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:04:53+00:00Added an answer on June 16, 2026 at 2:04 am

    Check this one,
    The Logic is as

    The final result will be in a ‘dictionary’.
    The ‘dictionary’ key contains the name as ‘Layer 1’
    The ‘dictionary’ value contains an ‘array’.
    The ‘array’ contains objects of ‘MinMax’.

    The MinMax class:

    @interface MinMax : NSObject
    
    @property(strong)NSString *minimum;
    @property(strong)NSString *maximum;
    
    @end
    

    The MyClass class:

    @interface MyClass : NSObject
    
    @property(strong) NSString *name;
    @property(strong) NSString *minimum;
    @property(strong) NSString *maximum;
    
    @end
    

    And the demo implementation:

    - (id)init
    {
        self = [super init];
        if (self) {
            _finalDict=[NSMutableDictionary new];
    
            MyClass *obj1=[MyClass new];
            obj1.name=@"Layer 1";
            obj1.minimum=@"1";
            obj1.maximum=@"30";
    
            MyClass *obj2=[MyClass new];
            obj2.name=@"Layer 1";
            obj2.minimum=@"45";
            obj2.maximum=@"60";
    
            MyClass *obj3=[MyClass new];
            obj3.name=@"Layer 2";
            obj3.minimum=@"45";
            obj3.maximum=@"60";
    
            _fromServerArrays=[[NSMutableArray alloc]initWithObjects:obj1, obj2, obj3, nil];
    
        }
        return self;
    }
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
    
        for (MyClass *obj in _fromServerArrays) {
            NSLog(@"From server  : %@, %@, %@", obj.name, obj.minimum, obj.maximum);
        }
    
    
        for (MyClass *myClassObj in _fromServerArrays) {
            MinMax *mmObj=[MinMax new];
            mmObj.minimum=myClassObj.minimum;
            mmObj.maximum=myClassObj.maximum;
    
            if ([_finalDict objectForKey:myClassObj.name]) {
                NSMutableArray *getArray=[_finalDict objectForKey:myClassObj.name];
                [getArray addObject:mmObj];
            }
            else{
                NSMutableArray *array=[NSMutableArray new];
                [array addObject:mmObj];
                [_finalDict setObject:array forKey:myClassObj.name];
            }
        }
    
    
        for (NSDictionary *dict in _finalDict) {
            NSLog(@"%@",dict);
            for (MinMax *mmObj in [_finalDict objectForKey:dict]) {
                NSLog(@"%@, %@", mmObj.minimum, mmObj.maximum);
            }
        }
    }
    

    Output:

    From server  : Layer 1, 1, 30
    From server  : Layer 1, 45, 60
    From server  : Layer 2, 45, 60
    Layer 1
    1, 30
    45, 60
    Layer 2
    45, 60
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this kind of array of data from a server (it dynamically changes):
I have some array data returned from an ajax call consisting of an image
I have a model that I'm trying to retrieve an array of data from,
I have one main array which is the returned data from a MySQL query
I have a problem related to an array data which fetched from an external
I have taken the data from database into array now I want it to
I have a variable that contains an array from form data, seen below: $option1
I have an accordion that binds data for each item from an array. I
I have this array Array ( [data] => Array ( [0] => Array (
If I want to have an ExpandableListView, which gets data from a response from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.