关于NSArray的问题

时间:2009-11-19 10:24:47

标签: iphone

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的值

2 个答案:

答案 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);
}
相关问题