我想将数组作为对象添加到另一个数组中.. 这就是为什么我这样做:
-(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。在日志中,我得到了临时值。
答案 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);
}