本文介绍了为什么我的NSMutableDictionary为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数组存储在NSMutableDictionary中.但是,在我将对象设置为NSMutableDictionary之后,该值将为null.这是我的代码,感谢您的帮助:
I am trying to store an array in a NSMutableDictionary. However the NSMutableDictionary is null after i have set objects to it. Here is my code any help is appreciated:
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
Initialize _dStockData
_dStockData = [[NSMutableDictionary alloc] init];
这篇关于为什么我的NSMutableDictionary为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!