• 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: NSPredicate and custom sort selector
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPredicate and custom sort selector


  • Subject: Re: NSPredicate and custom sort selector
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 29 May 2014 15:32:31 -0500

On May 29, 2014, at 2:52 PM, Trygve Inda wrote:

> I have an array of objects. One property of this object is a ratio stored as
> a string (e.g. 5:8, 9:4, 21:2) etc.
>
> I have a category on NSString:
>
> -(NSComparisonResult)compareAspectString:(NSString *)aString
>
> This does the division and compares the aspect ratios correctly.
>
> Now I need a predicate to do this.
>
> My Predicate says:
>
> Printing description of predicate:
> aspectRatio >[cd] "4:3"
>
> But it is just doing straight string comparison. How can I get the predicate
> to use by comparison method?

You can do this, but not using a predicate format string.

One approach would be to use +[NSComparisonPredicate predicateWithLeftExpression:rightExpression:customSelector:].  The selector there, though, isn't a comparator.  It returns TRUE if the comparison "passes"; FALSE otherwise.  For example, you would be implementing a "greater-than-ratio" comparison, so the custom selector when sent to one value and passed another value would return TRUE if and only if the first value (the receiver) is greater than (as a ratio) the second value (the argument).

Another approach would be +[NSPredicate predicateWithBlock:].

Regards,
Ken


_______________________________________________

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


  • Follow-Ups:
    • Re: NSPredicate and custom sort selector
      • From: Trygve Inda <email@hidden>
    • Re: NSPredicate and custom sort selector
      • From: Trygve Inda <email@hidden>
References: 
 >NSPredicate and custom sort selector (From: Trygve Inda <email@hidden>)

  • Prev by Date: NSPredicate and custom sort selector
  • Next by Date: Re: NSPredicate and custom sort selector
  • Previous by thread: NSPredicate and custom sort selector
  • Next by thread: Re: NSPredicate and custom sort selector
  • Index(es):
    • Date
    • Thread