Re: predicate with smallest x-coordinate?
Re: predicate with smallest x-coordinate?
- Subject: Re: predicate with smallest x-coordinate?
- From: David Spooner <email@hidden>
- Date: Thu, 8 Nov 2007 09:03:38 -0700
I doubt that a predicate well suited since it would have to know about
all Fish in order to determine whether or not a given Fish had the
smallest x-coordinate. Why not sort the array and take the first
element, or simply iterate over the list and take the smallest. You
could make the latter more visually pleasing by implementing a
category on NSArray...
@interface(NSArray)
- (id) leastObjectUsingSelector:(SEL)compareSelector;
@end
dave
On 8-Nov-07, at 8:17 AM, Bob Ueland wrote:
I have a Fish class with two ivars declared like this
@interface Fish : NSObject
{
NSString *name;
NSRect frame;
}
....
I create a NSMutableArray which contains a number of Fish objects.
When I want to filter out all Fish objects whose name begins with
letter B i use
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name
beginswith 'B'"];
That works. But now I want to filter out the Fish that has the
smallest x-coordinate (that is the smallest frame.origin.x). How
should I write my predicate?
Thanks Bob
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden