<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSPredicate",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPredicate"
  },
  "title" : "NSPredicate"
}
-->

# NSPredicate

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

```
class NSPredicate
```

## 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`](/documentation/Foundation/NSComparisonPredicate), [`NSCompoundPredicate`](/documentation/Foundation/NSCompoundPredicate), and [`NSExpression`](/documentation/Foundation/NSExpression), you often create predicates from a format string that the class methods parse on [`NSPredicate`](/documentation/Foundation/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](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Predicates/AdditionalChapters/Introduction.html#//apple_ref/doc/uid/TP40001789).

You can also create predicates that include variables using the [`evaluate(with:substitutionVariables:)`](/documentation/Foundation/NSPredicate/evaluate(with:substitutionVariables:)) method so that you can predefine the predicate before substituting concrete values at runtime.

## Topics

### Creating a Predicate

[`+  predicateWithFormat:`](/documentation/Foundation/NSPredicate/predicateWithFormat:)

Creates and returns a new predicate formed by creating a new string with a specified format and parsing the result.

[`+  predicateWithFormat:argumentArray:`](/documentation/Foundation/NSPredicate/init(format:argumentArray:))

Creates a predicate by substituting the values in a specified array into a format string and parsing the result.

[`+  predicateWithFormat:arguments:`](/documentation/Foundation/NSPredicate/init(format:arguments:))

Creates a predicate by substituting the values in an argument list into a format string and parsing the result.

[`init(format:_:)`](/documentation/Foundation/NSPredicate/init(format:_:))

Creates a predicate by substituting the values in an argument list into a format string and parsing the result.

[`init(_:)`](/documentation/Foundation/NSPredicate/init(_:))

Creates a predicate by converting an existing predicate.

[`-  predicateWithSubstitutionVariables:`](/documentation/Foundation/NSPredicate/withSubstitutionVariables(_:))

Returns a copy of the predicate and substitutes the predicates variables with specified values from a specified substitution variables dictionary.

[`+  predicateWithValue:`](/documentation/Foundation/NSPredicate/init(value:))

Creates and returns a predicate that always evaluates to a specified Boolean value.

[`+  predicateWithBlock:`](/documentation/Foundation/NSPredicate/init(block:))

Creates a predicate that evaluates using a specified block object and bindings dictionary.

[`+  predicateFromMetadataQueryString:`](/documentation/Foundation/NSPredicate/init(fromMetadataQueryString:))

Creates a predicate with a metadata query string.

### Evaluating a Predicate

[`-  evaluateWithObject:`](/documentation/Foundation/NSPredicate/evaluate(with:))

Returns a Boolean value that indicates whether the specified object matches the conditions that the predicate specifies.

[`-  evaluateWithObject:substitutionVariables:`](/documentation/Foundation/NSPredicate/evaluate(with:substitutionVariables:))

Returns a Boolean value that indicates whether the specified object matches the conditions that the predicate specifies after substituting in the values from a specified variables dictionary.

[`-  allowEvaluation`](/documentation/Foundation/NSPredicate/allowEvaluation())

Forces a securely decoded predicate to allow evaluation.

### Getting a String Representation

[`predicateFormat`](/documentation/Foundation/NSPredicate/predicateFormat)

The predicate’s format string.

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherited By

[`NSCompoundPredicate`](/documentation/Foundation/NSCompoundPredicate)

[`NSComparisonPredicate`](/documentation/Foundation/NSComparisonPredicate)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)