groupContentList = [[NSArray alloc] initWithObjects:
[Product productWithType:@"Device" name:@"iPhone"],
[Product productWithType:@"Device" name:@"iPod"],
[Product productWithType:@"Device" name:@"iPod touch"],
[Product productWithType:@"Desktop" name:@"iMac"],
[Product productWithType:@"Desktop" name:@"Mac Pro"],
[Product productWithType:@"Portable" name:@"iBook"],
[Product productWithType:@"Portable" name:@"MacBook"],
[Product productWithType:@"Portable" name:@"MacBook Pro"],
[Product productWithType:@"Portable" name:@"PowerBook"], nil];
如何打印groupcontestList的值
答案 0 :(得分:4)
您可以使用NSArray
方法检索表示-description
内容的字符串。这隐含地用于:
NSLog(@"%@", groupContentList);
它将依次对每个元素进行invoque -description
方法(默认为NSObject
中定义的打印对象的地址)。
因此,如果您希望它可用,则必须为-description
类定义Product
方法。
答案 1 :(得分:1)
For(Product* prod in groupContent){
NSLog(@"type=%@ name=%@", prod.type, prod.name);
}