Problem solved. Although predicates cannot involve transient properties, "you can follow relationships in a predicate using a key path". Obj-C Categories to the rescue…

For example, you can write a category on NSNumber containing a method - letterGrade. Then use this to create the leftExpression in the row template. Now everything works nicely, except you need to dig into the template after creating it, get the views and change the title of the menu item from "score.letterGrade" to something like "Letter Grade". But, in a real-life app, you need to do that for localization anyhow.


On 2009 Apr 18, at 05:03, Mike Abdullah wrote:

If it helps, the reason for Apple only supporting searching of persistent properties is for performance. If you're using the SQLite store for example, the predicate is not evaluated against the in- memory objects, but against the individual bits of data in the SQLite table. Of course, why Apple couldn't have then added automatic support for in-memory matching as the second step I don't know…

Yes, I figured something like that was going on but didn't want to get my hand slapped for trying to peek under Core Data's covers :)


I also tried Keary's suggestion, and learned some stuff that may be useful to have in the list archives...

On 2009 Apr 17, at 09:27, Keary Suska wrote:

I am not really up to speed on NSPredicateEditor, but could you use - ruleEditor:predicatePartsForCriterion:withDisplayValue:inRow: to "convert" the display case of grade = A-F to a predicate that is actually grade >= <= score range? I imagine you would need to construct a compound predicate with subpredicates (sub-rows). Either that or use the "BETWEEN" operator.

Good question.  Long answer:

The method you refer to is one of five delegate methods of the NSPredicate superclass NSRuleEditor, three of which the "delegate must implement". My guess is that implementing an NSPredicateEditor delegate is way to override the default row template generation. Might be what I need. However…

•  No documentation on how to implement a delegate.

• Delegate seems to be ignored. I sent -setDelegate:self and echoed it back at several points. I implemented the three required methods, returning nil or 0. Expected result: Probably empty rule editors. Actual result: None of my delegate methods ever get invoked and everything still works as before. Echoing back -delegate returns self as expected.

• Even if the delegate methods worked, I don't think I could implement them to return the required results. For example, ruleEditor:displayValueForCriterion:inRow: is supposed to return "The criterion for which the value is required". I know what a criterion is in English but to write code one needs something precise. No explanation in either this document or the Predicate Programming Guide. Oh, and the type of it is id :(

One clue I can find is that -criteriaForRow returns "the same [items] as those returned from the delegate method ruleEditor:child:forCriterion:withRowType:. Aha -- so I send - criteriaForRow for each row up to -numberOfRows, log the results and get an array like this:

2009-04-19 17:22:45.521 TestApp[52864:10b] criteria for row 2: (
    <_NSPredicateEditorItem: 0x15b71ce0 [Name]>,
    <_NSPredicateEditorItem: 0x15b6fbf0 [contains]>,
    <_NSPredicateEditorItem: 0x15b70e80 [<NSTextField: 0x15b50fe0>]>
)

I can see what they're doing -- these are the three subviews in the template. But notice the underscore prefix on _NSPredicateEditorItem. Since I can't create those, I'd need a way to get this "default" answer and then tweak it, and I have no idea how to do either.

Conclusion: Judging from these results and the lack of results in web searches, NSRuleEditor seems to be seldom used, NSPredicateEditor is rarely used, and probably delegate support in NSPredicateEditor is incomplete and unusable in Mac OS X 10.5.

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to