---
title: NSPredicate
framework: foundation
role: symbol
role_heading: Class
path: foundation/nspredicate
---

# NSPredicate

A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.

## Declaration

```swift
class NSPredicate
```

## Overview

Overview Predicates represent logical conditions, which you can use to filter collections of objects. Although it’s common to create predicates directly from instances of NSComparisonPredicate, NSCompoundPredicate, and NSExpression, you often create predicates from a format string that the class methods parse on NSPredicate. Examples of predicate format strings include: Simple comparisons, such as grade == "7" or firstName like "Juan" Case- and diacritic-insensitive lookups, such as name contains[cd] "stein" Logical operations, such as (firstName like "Mei") OR (lastName like "Chen") Temporal range constraints, such as date between {$YESTERDAY, $TOMORROW} Relational conditions, such as group.name like "work*" Aggregate operations, such as @sum.items.price < 1000 For a complete syntax reference, refer to the Predicate Programming Guide. You can also create predicates that include variables using the evaluate(with:substitutionVariables:) method so that you can predefine the predicate before substituting concrete values at runtime.

## Topics

### Creating a Predicate

- [init(format:argumentArray:)](foundation/nspredicate/init(format:argumentarray:).md)
- [init(format:arguments:)](foundation/nspredicate/init(format:arguments:).md)
- [init(format:_:)](foundation/nspredicate/init(format:_:).md)
- [init(_:)](foundation/nspredicate/init(_:).md)
- [withSubstitutionVariables(_:)](foundation/nspredicate/withsubstitutionvariables(_:).md)
- [init(value:)](foundation/nspredicate/init(value:).md)
- [init(block:)](foundation/nspredicate/init(block:).md)
- [init(fromMetadataQueryString:)](foundation/nspredicate/init(frommetadataquerystring:).md)

### Evaluating a Predicate

- [evaluate(with:)](foundation/nspredicate/evaluate(with:).md)
- [evaluate(with:substitutionVariables:)](foundation/nspredicate/evaluate(with:substitutionvariables:).md)
- [allowEvaluation()](foundation/nspredicate/allowevaluation().md)

### Getting a String Representation

- [predicateFormat](foundation/nspredicate/predicateformat.md)

### Initializers

- [init(coder:)](foundation/nspredicate/init(coder:).md)

### Instance Methods

- [allowEvaluation(validator:)](foundation/nspredicate/allowevaluation(validator:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [NSComparisonPredicate](foundation/nscomparisonpredicate.md)
- [NSCompoundPredicate](foundation/nscompoundpredicate.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Filltering

- [Predicate](foundation/predicate.md)
- [PredicateError](foundation/predicateerror.md)
- [PredicateCodableConfiguration](foundation/predicatecodableconfiguration.md)
- [PredicateCodableKeyPathProviding](foundation/predicatecodablekeypathproviding.md)
- [PredicateExpression](foundation/predicateexpression.md)
- [StandardPredicateExpression](foundation/standardpredicateexpression.md)
- [PredicateExpressions](foundation/predicateexpressions.md)
- [PredicateBindings](foundation/predicatebindings.md)
- [NSExpression](foundation/nsexpression.md)
- [NSComparisonPredicate](foundation/nscomparisonpredicate.md)
- [NSCompoundPredicate](foundation/nscompoundpredicate.md)
