On Mon, Jul 12, 2010 at 3:34 AM, Giannandrea Castaldi
<[email protected]> wrote:
> Hi,
> I want to use blocks to extract the min price and the max price from
> an NSArray of trips. I've found the following way:
>
> float minValue = 0.0;
> [someTrips enumerateObjectsUsingBlock:^(id obj, NSUInteger idx,
> BOOL *stop) {
> if (minValue == 0.0 || [[obj adultFinalPrice] floatValue] < minValue) {
> minValue = [obj floatValue];
> }
> }];
While I'm a big fan of blocks, for this particular use I think they're
overkill. You can get less, faster code by using a for/in loop:
float minValue = INFINITY;
for(id obj in someTrips)
minValue = MIN(minValue, [[obj adultFinalPrice] floatValue]);
Mike
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]