ios - How to split NSArray into multiple different arrays based on an NSArray of indexes? -


i have nsarray needs split multiple arrays. need split them based on indexes have in separate nsarray array. example, index array *arrayindexes looks this:

6 8 20 45 

these indexes need split single array on. there simple/quick way objective-c?

you can use subarraywithrange: go done, below example

nsarray *arr = [nsarray arraywithobjects:@"temp1",@"temp2",@"temp3",@"temp4",@"temp5",@"temp6",@"temp7",@"temp8",@"temp9",@"temp10",@"temp11",@"temp12",@"temp13",@"temp14",@"temp15",@"temp16",@"temp17",@"temp18", nil]; nsarray *arrindex = [nsarray arraywithobjects:@"4",@"10",@"12",@"14", nil]; nsmutablearray *arrtemp = [nsmutablearray new];  (int i=0;i<arrindex.count;i++) {     if (arrindex.count == i+1) {         [arrtemp addobject:[arr subarraywithrange:nsmakerange([arrindex[i-1] intvalue], arr.count - [arrindex[i-1] intvalue])]];     } else if (i==0) {         [arrtemp addobject:[arr subarraywithrange:nsmakerange(0, [arrindex[i] intvalue])]];     }else {         [arrtemp addobject:[arr subarraywithrange:nsmakerange([arrindex[i-1] intvalue],[arrindex[i] intvalue]-[arrindex[i-1] intvalue])]];     } } (nsarray *arr in arrtemp) {     nslog(@"arra - %@",arr); } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -