-1

我尝试使用来自 NSArray 的数据创建对象的 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 不包含任何内容,而条目的数据有两个输入?

谢谢

4

1 回答 1

0

您没有初始化nameInsert数组。

代替

NSMutableArray *nameInsert;

NSMutableArray *nameInsert = [NSMutableArray arrayWithCapacity:entries.count];
于 2013-08-21T16:54:53.410 回答