我有一個NSMutableArray
(tripHistory),它每秒都會用新數據添加一個NSMutableDictionary
(currentUpdate)。字典數組,空字典,保持數組數據
[currentUpdate setObject:testVariable forKey:@"Test"];
[tripHistory addObject:currentUpdate];
[currentUpdate removeAllObjects];
然而,當我遍歷tripHistory
調用[[tripHistory objectAtIndex:i] description]
一切都是空。
我的循環如下:
for (int i=0; i<[tripHistory count]; i++)
{
NSLog(@"%@", [[tripHistory objectAtIndex:i] description]);
}
要初始化我的變量,下面的代碼只對第一次更新調用。
tripHistory = [[NSMutableArray alloc] init];
currentUpdate = [[NSMutableDictionary alloc] init];
任何想法?
如何在啓用ARC的情況下強制釋放它? – Baub
明白了!我只是currentUpdate = [[NSMutableDictionary alloc] init];每次更新。 – Baub
你不知道。當你開始下一次更新時,只需重新分配一個新的字典:'currentUpdate = [NSMutableDictionary alloc] init];' –