//1.创建一个可变数组
NSMutableArray *mArray = [NSMutableArray arrayWithObjects:@"a",@"b",@"a",@"b",@"a",@"b",@"a",@"b",nil];
NSMutableArray *A = [NSMutableArray array];
NSMutableArray *B = [NSMutableArray array];
for(int i =0; i < mArray.count; i++) {
if(i % 2 == 0) {
[A addObject:mArray[i]];
}else{
[B addObject:mArray[i]];
}
}
XPFLog(@"双数%@单数%@", A, B);
打印结果:
双数(
a,
a,
a,
a
)
单数(
b,
b,
b,
b
)