我尝试使用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在条目的数据有两个输入时什么都不包含?
由于
答案 0 :(得分:0)
您没有初始化nameInsert
数组。
替换
NSMutableArray *nameInsert;
与
NSMutableArray *nameInsert = [NSMutableArray arrayWithCapacity:entries.count];