• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: predicate with smallest x-coordinate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >predicate with smallest x-coordinate? (From: Bob Ueland <email@hidden>)

  • Prev by Date: Programatically Editing and NSTokenFieldCell (Inside an NSTextView)
  • Next by Date: Re: [<NSCFArray> removeObserver:forKeyPath:] is not supported
  • Previous by thread: predicate with smallest x-coordinate?
  • Next by thread: Changing settings in System Preferences using cocoa api
  • Index(es):
    • Date
    • Thread