我正在掃描字典的NSMutableArray,並向WebService請求每個數據的信息。在NSMutableArray中添加NSMutableDictionary
問題是獲取數據後,我需要更新相同數組字典的2個鍵,當我添加一個對象時,數組繼續爲空。
有什麼問題?
PS:使用ARC
NSMutableArray* arrayOfDicts = [NSMutableArray arrayWithObjects:
[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"2013",@"year",
@"a1beb511-7fe1-434b-ab87-a0d02fb47713",@"yearTB",
@"",@"receita_arrecadada",
@"",@"receita_prevista_atualizada",
nil],
[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"2012",@"year",
@"5d20f841-d790-4671-ae26-505c9a8c7f76",@"yearTB",
@"",@"receita_arrecadada",
@"",@"receita_prevista_atualizada",
nil],
nil];
__block NSMutableArray* arrayTemp = [[NSMutableArray alloc] init];;
__block NSMutableDictionary* dicTemp;
for(dicTemp in arrayOfDicts){
NSString* year = [dicTemp objectForKey:@"year"];
NSString* yearTB = [dicTemp objectForKey:@"yearTB"];
NSMutableDictionary *newDict = [[NSMutableDictionary alloc] init];
[RequestFacade getReceiptsTotalInYear:[NSString stringWithFormat:@"%@", yearTB] andCompletion:^(Receipt *receipt) {
//NSLog(@"%@",receipt.receita_arrecadada); // Print the correct actual value
[newDict addEntriesFromDictionary:dicTemp];
[newDict setObject:year forKey:@"year"];
[newDict setObject:yearTB forKey:@"yearTB"];
[newDict setObject:receipt.receita_arrecadada forKey:@"receita_arrecadada"];
[newDict setObject:receipt.receita_atualizada forKey:@"receita_atualizada"];
[arrayTemp addObject:newDict];
NSLog(@"%@", arrayTemp); // shows me the array of dicts
// until here, its ok!
}];
}
NSLog(@"%@", arrayTemp); // shows me an empty array...F*CK!
首先初始化arrayOfDict。 – iProgrammer