我正在尝试将数组存储在 NSMutableDictionary 中。但是,在我为其设置对象后,NSMutableDictionary 为空。这是我的代码,感谢任何帮助:
NSMutableArray *arrTemp = [[NSMutableArray alloc] init];
NSMutableDictionary *dTemp = [[NSMutableDictionary alloc] init];
STStockData *stockData = [[STStockData alloc] init];
for (int i = 0; i < [_arrTickers count]; i++) {
// get the ticker from its json form
dTemp = [_arrTickers objectAtIndex:i];
NSLog(@"Ticker: %@",[dTemp objectForKey:@"ticker"]);
// gets current data for ticker
[arrTemp addObjectsFromArray:[stockData getCurrentStockDataForTicker:[dTemp objectForKey:@"ticker"]]];
NSLog(@"Price %@",[arrTemp objectAtIndex:1]); // just to prove the array isnt nil.
// adds it to the dictionary
[_dStockData setObject:arrTemp forKey:[dTemp objectForKey:@"ticker"]];
NSLog(@"Dictionary %@",_dStockData);
// remove all objects so can reuse.
[arrTemp removeAllObjects];
dTemp = nil; // can't remove objects using [removeAllObjects] method. believe its due to it holding inside NSArrays which are immutable.
}
这是控制台输出:
初始化_dStockData
_dStockData = [[NSMutableDictionary alloc] init];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)