iOS - 截取数组前几个元素放入新的数组,剩余的放入另外一个数组

 

NSArray *array = [NSArray arrayWithObjects:@"Crystal",@"Maisie",@"Lukas",@"Ruben",@"Brooklynn",@"Melody",@"Imogen",@"Skye",@"Rafael",@"Lindsey",@"Felix",nil];
    NSArray *topThree = [array subarrayWithRange:NSMakeRange(0, 3)];
    NSArray *remaining = [array subarrayWithRange:NSMakeRange(3, array.count-3)];
    NSLog(@"topThree:%@=======remaining:%@",topThree,remaining);





topThree:[
Crystal,
Maisie,
Lukas
]=======remaining:[
Ruben,
Brooklynn,
Melody,
Imogen,
Skye,
Rafael,
Lindsey,
Felix
]

 

posted @ 2019-05-13 15:36  公羽寒  阅读(10176)  评论(0编辑  收藏  举报