-1

使用ARC時,在創建for循環中的NSDictionaries時遇到了很大的麻煩。關鍵是,第一個「字典」創建後,應用程序崩潰給予EXC_BAD_ACCESS,所以我認爲這是與對象的釋放相關的東西,但無法弄清楚什麼!我試圖用一個autoreleasepool但結果是一樣的使用ARC在循環中創建NSDictionary

for (int i = 0; i < [arr1 count]; i++) { 
     __strong NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[arr1 objectAtIndex:i], @"name", [arr4 objectAtIndex:i], @"position", [arr2 objectAtIndex:i], @"number", [arr5 objectAtIndex:i], @"status", [[arr6 objectAtIndex:i] intValue], @"order", nil]; 
     [pl_stuff addObject:dict]; 
} 

感謝您的答覆

+0

是什麼pl_stuff? – 2012-08-06 12:53:58

+0

arr1的內容是什麼 – NIKHIL 2012-08-06 12:56:06

+0

pl_stuff是一個數組,問題是,正如弗拉基米爾提到的那樣,我在插入到數組中的字典中添加了一個int。感謝您的快速回答 – 2012-08-06 12:59:29

回答

4
[[arr6 objectAtIndex:i] intValue] 

你試圖純整數值添加到您的陣列,但陣列只接受Objective-C對象。你應該見好就收,作爲:

[arr6 objectAtIndex:i] 
+0

oh gosh,我沒有想到在字典中插入一個int,然後在數組中插入字典的問題。那是這個問題,非常感謝 – 2012-08-06 12:58:06