Iphone 关于NSArray的问题
如何打印GroupCompetingList的值您可以使用Iphone 关于NSArray的问题,iphone,Iphone,如何打印GroupCompetingList的值您可以使用-description方法检索表示NSArray内容的字符串。这与以下内容一起使用: groupContentList = [[NSArray alloc] initWithObjects: [Product productWithType:@"Device" name:@"iPhone"], [Product productWithType:@"Devic
-description
方法检索表示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];
For(Product* prod in groupContent){
NSLog(@"type=%@ name=%@", prod.type, prod.name);
}
它将依次在每个元素上调用-description
方法(默认为NSObject
中定义的对象的打印地址)
因此,如果您希望它可用,您必须为
产品类定义-description
方法。您可以使用-description
方法检索表示NSArray
内容的字符串。这与以下内容一起使用:
For(Product* prod in groupContent){
NSLog(@"type=%@ name=%@", prod.type, prod.name);
}
它将依次在每个元素上调用-description
方法(默认为NSObject
中定义的对象的打印地址)
因此,如果希望它可用,就必须为产品
类定义一个-description
方法