Main

Core Data Archives

June 26, 2006

CoreData NSExpression descendants

Q: What is a NSSelfExpression? What about NSKeyPathExpression?

A: No way to know it using the documentation, those two classes extend NSExpression but the only reference found in Xcode documentation is for NSKeyPathExpression:

typedef enum {

NSConstantValueExpressionType = 0,

NSEvaluatedObjectExpressionType,

NSVariableExpressionType,

NSKeyPathExpressionType,

NSFunctionExpressionType

} NSExpressionType;

Searching for it with Google returns only 3 results (THREE!) and thirteen for NSSelfExpression.

The two more "helpful":

1. NSExpression.m source code file from OpenGroupware.org libFoundation library.

2. A presentation from BigNerdRanch:ExploringCoreData.pdf.gz that just shows the class hierarchy for NSExpression.

So what?

In the general case you don't need to work with those classes but when you do, you will have to dig to find any information about them.

I haven't found yet all the uses of these two classes but I have seen them in the following two cases:

1. NSSelfExpression

When you have your Core Data model, with an integer property (for example) you can set an attribute of minimum and maximum for that property.

Those two attributes for the property are "compiled" into a NSComparisonPredicate.

In the case of the minimum attribute ( and maximum ) the NSComparisonPredicate is composed of two NSExpression: an NSSelfExpression for the "left side" expression and a NSConstantValueExpression for the "right side" (which suffers the same documentation "abundance").

This two expressions combined in the predicate gives the evaluation: [your numeric property instance value] >= [your minimum]

selfexpressionsides.png

2. NSKeyPathExpression

The same applies for this one, but to evaluate a different attribute: length for a String type property.

For the "left side" expression you have the NSKeyPathExpression and for the "right side" a NSConstantValueExpression, giving you the evaluation of length >= [your minimum length] applied to the property instance.

If you look at the source code file from OpenGroupware.org they are both very simple classes, maybe that is one of the reasons for its anonymity in the documentation.

I will document all their uses I found and I will post them in blog entries, in the mean time I will file a documentation enhancement at Apple's Bug Reporter.

About Core Data

This page contains an archive of all entries posted to [Brain dump] in the Core Data category. They are listed from oldest to newest.

Cocoa is the previous category.

Everything else is the next category.

Many more can be found on the main index page or by looking through the archives.