将数组添加到另一个数组作为对象

时间:2013-12-17 14:03:41

标签: ios ios7 nsmutablearray nsarray

我想将数组作为对象添加到另一个数组中.. 这就是为什么我这样做:

-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{
   int id=0;
   NSLog(@"Array is%@",ary);
   NSArray *temp;
   for(int i=0;i<[ary count];i++){
       temp=[ary objectAtIndex:i];
       id=[[temp objectAtIndex:4] integerValue];
       NSLog(@"temp is%@ %d",temp,id);
      // [MyAppDelegate.searchResultArray addobject:temp];
   }
   NSLog(@"%@",MyAppDelegate.searchResultArray);
}

但是在Log中我在MYAppDelegate.searchResultArray中变为null。在日志中,我得到了临时值。

1 个答案:

答案 0 :(得分:0)

试试这个......

-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{
 int id=0;
 NSLog(@"Array is%@",ary);
 NSMutableArray *temp;
 for(int i=0;i<[ary count];i++){
temp=[ary objectAtIndex:i];
    NSLog(@"string%@",[temp objectAtIndex:8]);
if(id==[[temp objectAtIndex:4] integerValue]){
    NSLog(@"inside");
    NSMutableArray *temp1=[[NSMutableArray alloc]init];
    temp1=[MyAppDelegate.searchResultArray objectAtIndex:i-1];
    NSLog(@"temp1%@",temp1);
    NSString *tempStr=[[temp1 objectAtIndex:8] stringByAppendingString:[temp objectAtIndex:8]];
    NSLog(@"%@",tempStr);
    [temp1 replaceObjectAtIndex:8 withObject:tempStr];
    [MyAppDelegate.searchResultArray replaceObjectAtIndex:i-1 withObject:temp1];
}
else{
id=[[temp objectAtIndex:4] integerValue];
NSLog(@"temp is%@ %d",temp,id);
[MyAppDelegate.searchResultArray addObject:temp];
}
}
NSLog(@"%@",MyAppDelegate.searchResultArray);
}
相关问题