Re: Use of blocks

2010-07-12 Thread Thomas Clement
On 12 juil. 2010, at 14:23, Giannandrea Castaldi wrote: > On Mon, Jul 12, 2010 at 9:43 AM, vincent habchi wrote: >> Buongiorno :) >> >> Le 12 juil. 2010 à 09:34, Giannandrea Castaldi a écrit : >> >>> I want to use blocks to extract the min price and the max price from >>> an NSArray of trips.

Re: Use of blocks

2010-07-12 Thread Marcelo Alves
On 12/07/2010, at 04:34, Giannandrea Castaldi wrote: > I've also looked for a solution with NSExpression and NSPredicate with > the function min/max but if I've correctly understood the use of > NSExpression and NSPredicate with such functions is only for CoreData. > Thanks. See the "Set and Ar

Re: Use of blocks

2010-07-12 Thread Preston Sumner
You can use key-path collection operators, assuming someTrips is a property of self: NSNumber *minPrice = [self valueForKeyPath:@"sometri...@min.adultfinalprice"]; NSNumber *maxPrice = [self valueForKeyPath:@"sometri...@max.adultfinalprice"]; By the way, minValue and maxValue in your e

Re: Use of blocks

2010-07-12 Thread Giannandrea Castaldi
Yes, as already suggested by Preston, key path operators are very expressive. Thanks for the suggestions. Jean On Mon, Jul 12, 2010 at 4:31 PM, Keith Duncan wrote: >> overkill. You can get less, faster code by using a for/in loop: >> >> float minValue = INFINITY; >> for(id obj in someTrips) >>  

Re: Use of blocks

2010-07-12 Thread Keith Duncan
> 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]); You could get even less, more expressive code, using key path operators: NSNumber *minValue = [someTrips

Re: Use of blocks

2010-07-12 Thread Michael Ash
On Mon, Jul 12, 2010 at 3:34 AM, Giannandrea Castaldi 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 *s

Re: Use of blocks

2010-07-12 Thread Giannandrea Castaldi
On Mon, Jul 12, 2010 at 9:43 AM, vincent habchi wrote: > Buongiorno :) > > Le 12 juil. 2010 à 09:34, Giannandrea Castaldi a écrit : > >> 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; >>    [

Re: Use of blocks

2010-07-12 Thread vincent habchi
Buongiorno :) Le 12 juil. 2010 à 09:34, Giannandrea Castaldi a écrit : > 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, > B

Use of blocks

2010-07-12 Thread Giannandrea Castaldi
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] <