2013-08-21 82 views
-1

我嘗試使用NSArray中的數據創建對象的NSArray。所以,我試圖複製下面自動用NSDictionary在NSArray中插入對象

這裏對象的插入是起始位置

candyArray = [NSArray arrayWithObjects: 
        [Candy candyOfCategory:@"chocolate" name:@"chocolate bar"], 
        [Candy candyOfCategory:@"chocolate" name:@"chocolate chip"], 
        [Candy candyOfCategory:@"chocolate" name:@"dark chocolate"], 
        [Candy candyOfCategory:@"hard" name:@"lollipop"], 
        [Candy candyOfCategory:@"hard" name:@"candy cane"], 
        [Candy candyOfCategory:@"hard" name:@"jaw breaker"], 
        [Candy candyOfCategory:@"other" name:@"caramel"], 
        [Candy candyOfCategory:@"other" name:@"sour chew"], 
        [Candy candyOfCategory:@"other" name:@"peanut butter cup"], 
        [Candy candyOfCategory:@"other" name:@"gummi bear"], nil]; 

這是我嘗試自動

NSArray *entries = [feed objectForKey:@"bookmarks"]; 

NSMutableArray *nameInsert; 

for (NSDictionary *item in entries) 
{ 
    [nameInsert addObject: [Candy candyOfCategory:@"chocolate" name:[item objectForKey:@"name"]]]; 
} 

candyArray = nameInsert; 

爲什麼nameInsert包含什麼,而條目的數據有兩個輸入?

謝謝

回答

0

您未初始化nameInsert陣列。

更換

NSMutableArray *nameInsert; 

NSMutableArray *nameInsert = [NSMutableArray arrayWithCapacity:entries.count]; 
+0

我的應用程序的工作 非常感謝您 –

+0

@約翰史密斯不客氣,隨意接受的答案,如果它幫助你:) –