Fetch last five values from NSMutableArray

后端 未结 3 1093
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 10:04

I have a NSMutableArray whose count is 10 and I want to extract the last 5 values and store them in another array. How can I do this?

3条回答
  •  遥遥无期
    2021-01-29 10:48

    Use following way :

     NSMutableArray *first = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
    
        NSMutableArray *sec = [[NSMutableArray alloc] init];
        for(int i=5; i< [first count]; i++) {
    
            [sec addObject:[first objectAtIndex:i]];
    
         }
    
    NSLog(@"sec - %@",sec);
    

提交回复
热议问题