Objective c 错误:从NSMutableArray获取对象-目标C
我有以下代码:Objective c 错误:从NSMutableArray获取对象-目标C,objective-c,class,Objective C,Class,我有以下代码: Product product = [[Product alloc] init]; product.title = tag; [allProducts addObject:product]; NSString *pImage = [[NSString alloc] initWithFormat:p.title]; 但它没有归还任何东西 谁能帮我一下吗? 谢谢代码中没有任何内容试图从集合中检索任何内容 [allProducts addObject:product]; 上面的行
Product product = [[Product alloc] init];
product.title = tag;
[allProducts addObject:product];
NSString *pImage = [[NSString alloc] initWithFormat:p.title];
但它没有归还任何东西
谁能帮我一下吗?
谢谢代码中没有任何内容试图从集合中检索任何内容
[allProducts addObject:product];
上面的行用于添加对象。如果要检索对象,请执行以下操作:
Product* product = [allProducts objectAtIndex:0];
请参阅和NSMutableArray的文档
--更新--
刚刚注意到您的代码中有一个错误:
Product* product = [[Product alloc] init];
(您遗漏了*)应该是Product*Product=[[Product alloc]init];您刚刚添加了一个额外的
]
:)@Toastor-oooooooops:)