> 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 > >
I am doing this in an NSPredicateEditor and I am building template rows programmatically. On the left I have as one of the options "aspect ratio" then in the middle I have the menu filled with "equal to, not equal to" (those work fine) but if I add in a third "is greater than", how can I have it build the right predicate? Eg. (aspect ratio) (is greater than) 4:3 Where 4:3 is the text the user enters in the field. My template row creation looks like: template = [[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:expressions rightExpressionAttributeType:attributeType modifier:NSDirectPredicateModifier operators:operators options:options]; Expressions are built with [NSExpression expressionForKeyPath:keyPath] AttributeType is NSStringAttributeType Operators (that work) include NSEqualToPredicateOperatorType but I am trying to add (and make work) NSGreaterThanPredicateOperatorType Options is 0 _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com