Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSPredicate

Inherits from
Implements
Package
com.apple.cocoa.foundation
Availability
Available in Mac OS X v10.4 and later.
Companion guide

Overview

The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.

You use predicates to represent logical conditions, used for describing objects in persistent stores and in-memory filtering of objects. You often create predicates from a format string which is parsed by the class methods on NSPredicate; examples include:

You can create predicates for relationships, such as:

You can also create predicates for operations, such as @sum.items.price < 1000.

In general, the order for like and matches predicates is propertyName OPERATOR pattern.

It is also common to create predicates directly—this is more efficient, more (type-)safe, and it avoids localization issues.

You can also create predicates that include variables, so that they can be pre-defined (in a tool) before substituting concrete values at runtime. For predicates that use variables, evaluation is a two step process (see predicateWithSubstitutionVariables and evaluateWithObject).

Tasks

Constructors

Creating Predicates

Evaluating

Getting Format Information

Constructors

NSPredicate

public NSPredicate()

Discussion

Creates an empty NSPredicate object.

Availability

Static Methods

predicateWithFormat

Returns a new predicate by substituting the values in arguments into predicateFormat in the order they appear, and parsing the result.

public static NSPredicate predicateWithFormat(String predicateFormat, NSArray arguments)

Availability

predicateWithValue

public static NSPredicate predicateWithValue(boolean value)

Discussion

Returns a predicate that always evaluates to value.

Availability

Instance Methods

evaluateWithObject

Returns true if object matches the conditions specified by the receiver; otherwise false

public boolean evaluateWithObject(Object object)

Discussion

.

Availability

predicateFormat

public String predicateFormat()

Discussion

Returns the receiver’s format string.

Availability

predicateWithSubstitutionVariables

Returns a copy of the receiver with the receiver’s variables substituted by values specified in the substitution variables dictionary.

public NSPredicate predicateWithSubstitutionVariables(NSDictionary variables)

Discussion

The substitution variables dictionary is specified by variables which must contain key-value pairs for all variables in the predicate.

The receiver itself is not modified by this method, so you can reuse it for any number of substitutions.

Availability


Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.