NSMutableArray *newarr=[NSMutableArray arrayWithArray:shoppingCart]; // NSUInteger count1=[set countForObject:@"iPod5"]; // NSUInteger count2=[set countForObject:@"iPhone6s"]; // NSUInteger count3=[set countForObject:@"iPhone6"]; int count1=0,count2=0,count3=0; for(NSDictionary *dic in newarr){ if([dic[keyProductName] isEqual:@"iPod5"]){ count1++; } if([dic[keyProductName] isEqual:@"iPhone6"]){ count2++; } if([dic[keyProductName] isEqual:@"iPhone6s"]){ count3++; } } NSSet *set=[NSSet setWithArray:newarr]; for(NSDictionary *dic in set){ int coun=[dic[keyProductPrice] intValue]; if([dic[keyProductName] isEqual:@"iPod5"]){ NSLog(@"商品名称:%@,数量:%d,单价:%@,合计:%d",dic[keyProductName],count1,dic[keyProductPrice],count1*coun);} if([dic[keyProductName] isEqual:@"iPhone6"]){ NSLog(@"商品名称:%@,数量:%d,单价:%@,合计:%d",dic[keyProductName],count2,dic[keyProductPrice],count2*coun); } if([dic[keyProductName] isEqual:@"iPhone6s"]){ NSLog(@"商品名称:%@,数量:%d,单价:%@,合计:%d",dic[keyProductName],count3,dic[keyProductPrice],count3*coun); } }