<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPredicateEditorRowTemplate",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPredicateEditorRowTemplate"
  },
  "title" : "NSPredicateEditorRowTemplate"
}
-->

# NSPredicateEditorRowTemplate

A template that describes available predicates and how to display them.

```
class NSPredicateEditorRowTemplate
```

## Overview

You can create instances of `NSPredicateEditorRowTemplate` programmatically or in Interface Builder. By default, a noncompound row template has three views: a popup (or static text field) on the left, a popup or static text field for operators, and either a popup or other view on the right.  You can subclass `NSPredicateEditorRowTemplate` to create a row template with different numbers or types of views.

`NSPredicateEditorRowTemplate` is a concrete class, but it has five primitive methods that are called by [`NSPredicateEditor`](/documentation/AppKit/NSPredicateEditor): [`templateViews`](/documentation/AppKit/NSPredicateEditorRowTemplate/templateViews), [`match(for:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/match(for:)), [`setPredicate(_:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/setPredicate(_:)), [`displayableSubpredicates(of:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/displayableSubpredicates(of:)), and [`predicate(withSubpredicates:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/predicate(withSubpredicates:)). `NSPredicateEditorRowTemplate` implements all of these methods, but you can override them for custom templates. The primitive methods are used by an instance of `NSPredicateEditor` as follows.

First, an instance of `NSPredicateEditor` is created, and some row templates are set on it—either through a nib file or programmatically. The first thing predicate editor does is ask each of the templates for their views, using [`templateViews`](/documentation/AppKit/NSPredicateEditorRowTemplate/templateViews).

After setting up the predicate editor, you typically send it a [`objectValue`](/documentation/AppKit/NSControl/objectValue) message to restore a saved predicate. `NSPredicateEditor` needs to determine which of its templates should display each predicate in the predicate tree. It does this by sending each of its row templates a [`match(for:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/match(for:)) message and choosing the one that returns the highest value.

After finding the best match for a predicate, `NSPredicateEditor` copies that template to get fresh views, inserts them into the proper row, and then sets the predicate on the template using [`setPredicate(_:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/setPredicate(_:)). Within that method, the `NSPredicateEditorRowTemplate` object must set its views’ values to represent that predicate.

`NSPredicateEditorRowTemplate` next asks the template for the “displayable sub-predicates” of the predicate by sending a [`displayableSubpredicates(of:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/displayableSubpredicates(of:)) message. If a template represents a predicate in its entirety, or if the predicate has no subpredicates, it can return `nil` for this.  Otherwise, it should return a list of predicates to be made into sub-rows of that template’s row. The whole process repeats for each sub-predicate.

At this point, the user sees the predicate that was saved.  If the user then makes some changes to the views of the templates, this causes `NSPredicateEditor` to recompute its predicate by asking each of the templates to return the predicate represented by the new view values, passing in the subpredicates represented by the sub-rows (an empty array if there are none, or `nil` if they aren’t supported by that predicate type):

[`predicate(withSubpredicates:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/predicate(withSubpredicates:))

## Topics

### Initializing a Template

[`init(leftExpressions:rightExpressions:modifier:operators:options:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/init(leftExpressions:rightExpressions:modifier:operators:options:))

Initializes and returns a “pop-up-pop-up-pop-up”–style row template.

[`init(leftExpressions:rightExpressionAttributeType:modifier:operators:options:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/init(leftExpressions:rightExpressionAttributeType:modifier:operators:options:))

Initializes and returns a “pop-up-pop-up-view”–style row template.

[`init(compoundTypes:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/init(compoundTypes:))

Initializes and returns a row template suitable for displaying compound predicates.

### Core Data Integration

[`templates(withAttributeKeyPaths:in:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/templates(withAttributeKeyPaths:in:))

Returns an array of predicate templates for the given attribute key paths for a given entity.

### Primitive Methods

[`match(for:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/match(for:))

Returns a positive number if the receiver can represent a given predicate, and `0` if it cannot.

[`templateViews`](/documentation/AppKit/NSPredicateEditorRowTemplate/templateViews)

Returns the views that display this template’s predicate.

[`setPredicate(_:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/setPredicate(_:))

Sets the value of the views according to the given predicate.

[`displayableSubpredicates(of:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/displayableSubpredicates(of:))

Returns the subpredicates that should be made sub-rows of a given predicate.

[`predicate(withSubpredicates:)`](/documentation/AppKit/NSPredicateEditorRowTemplate/predicate(withSubpredicates:))

Returns the predicate represented by the receiver’s views’ values and the given sub-predicates.

### Information About a Row Template

[`leftExpressions`](/documentation/AppKit/NSPredicateEditorRowTemplate/leftExpressions)

Returns the left hand expressions for the receiver.

[`rightExpressions`](/documentation/AppKit/NSPredicateEditorRowTemplate/rightExpressions)

Returns the right hand expressions for the receiver.

[`compoundTypes`](/documentation/AppKit/NSPredicateEditorRowTemplate/compoundTypes)

Returns the compound predicate types.

[`modifier`](/documentation/AppKit/NSPredicateEditorRowTemplate/modifier)

Returns the comparison predicate modifier for the receiver.

[`operators`](/documentation/AppKit/NSPredicateEditorRowTemplate/operators)

Returns the array of comparison predicate operators.

[`options`](/documentation/AppKit/NSPredicateEditorRowTemplate/options)

Returns the comparison predicate options.

[`rightExpressionAttributeType`](/documentation/AppKit/NSPredicateEditorRowTemplate/rightExpressionAttributeType)

Returns the attribute type of the receiver’s right expression.



---

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)