Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 拆分数组并获取索引_Ios_Objective C_Nsmutablearray - Fatal编程技术网

Ios 拆分数组并获取索引

Ios 拆分数组并获取索引,ios,objective-c,nsmutablearray,Ios,Objective C,Nsmutablearray,我有一个这样的数组 [ 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1 ] 在上面的数组中,我需要对0和1数字以及它们的索引进行拆分。我编写了在单独的数组中获取0和1的代码,但我希望它们的索引也在主数组中,下面的代码是: for (int i = 0; i < [Array count]; i++) { NSString* strV = [Array objectAtIndex:i]; NSLog(

我有一个这样的数组

[
  1,
  1,
  1,
  0,
  0,
  0,
  1,
  1,
  0,
  1,
  1
]
在上面的数组中,我需要对
0
1
数字以及它们的
索引进行拆分。我编写了在单独的数组中获取
0
1
的代码,但我希望它们的索引也在主数组中,下面的代码是:

for (int i = 0; i < [Array count]; i++) {
       NSString* strV = [Array objectAtIndex:i];
        NSLog(@"ArrayCount:%@",strV);
         if ([strV isEqual:[NSNumber numberWithInt:0]]) {
                [getArray addObject:strV];
                   }
    }

    NSLog(@"getArray:%@",getArray.description);
}
for(int i=0;i<[数组计数];i++){
NSString*strV=[Array objectAtIndex:i];
NSLog(@“ArrayCount:%@),strV);
如果([strV isEqual:[NSNumber Number Withint:0]]){
[getArray addObject:strV];
}
}
NSLog(@“getArray:%@”,getArray.description);
}
那么,我怎样才能得到
0
的索引,你能帮我吗。谢谢你

NSArray*mainArr=@[@1,1,0,0,1,1,1,0,1];
NSMutableArray *arrayContainZero = [NSMutableArray new];
NSMutableArray *arrayWithZeroIndexes = [NSMutableArray new];
for (NSNumber *numberZero in Array)
{
    if(numberZero.integerValue == 0)
    {
            [arrayContainZero addObject:numberZero];
            [arrayWithZeroIndexes      addObject:@([arrayContainZeroindexOfObject:numberZero])];

    }
}
NSMutableArray*tempArr=[[NSMutableArray alloc]init];
for(int i=0;iArray没有索引路径。如果您想要索引,您已经有了索引;它是循环计数器(
i
)。您希望为索引使用单独的数组还是同一数组也应包含索引0?同一数组应包含0和1。首先,我需要在主数组中的索引位置为0和1之后将0和1分开。您的问题非常不清楚。什么是“在
0
1”上进行拆分数字是什么意思?你想要什么输出?你想要把所有的
1`数字放在一个输出数组中,把所有的
0
数字放在第二个输出数组中?然后你说你想要它们的索引。所以你想要两个包含其他对象的新数组(字典?)包含
1
0
数字以及原始数组中的索引的?
 NSArray *mainArr=@[@1,@1,@1,@0,@0,@0,@1,@1,@0,@1,@1];
    NSMutableArray *tempArr=[[NSMutableArray alloc] init];
    for(int i=0;i<[mainArr count];i++){
        if([[mainArr objectAtIndex:i] isEqualToNumber:[NSNumber numberWithInt:0]]){
            NSMutableArray *arr=[[NSMutableArray alloc] initWithArray:tempArr];
            [tempArr removeAllObjects];
            NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0],@"value",[NSNumber numberWithInt:i],@"index",nil];
            [tempArr addObject:dic];
            [tempArr addObjectsFromArray:arr];
        }else if ([[mainArr objectAtIndex:i] isEqualToNumber:[NSNumber numberWithInt:1]]){
            NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1],@"value",[NSNumber numberWithInt:i],@"index",nil];
            [tempArr addObject:dic];
        }
    }

    NSLog(@"%@",tempArr.description);