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.
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
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
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)
>>
> 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
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
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;
>> [
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
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] <