开发者

Question about the NSArray

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];

How to print the value of groupcontestList


You can retrieve a string representing NSArray contents with -description method. This is implicitely used with:

NSLog(@"%@", groupContentList);

It will in turn invoque -description method on each of its elements (which defaults to printing address of object as defined in NSObject).

So if you want it to be usable, you have to define a -description method for your Product class.


For(Product* prod in groupContent){
    NSLog(@"type=%@ name=%@", prod.type, prod.name);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜