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

# NSWhoseSpecifier

A specifier that indicates every object in a collection matching a condition.

```
class NSWhoseSpecifier
```

## Overview

`NSWhoseSpecifier` specifies every object in a collection (or every element in a container) that matches the condition defined by a single Boolean expression or multiple Boolean expressions connected by logical operators. `NSWhoseSpecifier` is unique among object specifiers in that its top-level container is typically not the application object but an evaluated object specifier involved in the tested-for condition. An `NSWhoseSpecifier` object encapsulates a “test” object for defining this condition. A test object is instantiated from a subclass of the abstract [`NSScriptWhoseTest`](/documentation/Foundation/NSScriptWhoseTest) class, whose one declared method is [`isTrue()`](/documentation/Foundation/NSScriptWhoseTest/isTrue()). See “Boolean Expressions and Logical Operations” in [`NSScriptObjectSpecifier`](/documentation/Foundation/NSScriptObjectSpecifier) and the descriptions in NSComparisonMethods and NSScriptingComparisonMethods for more information.

The set of elements specified by an `NSWhoseSpecifier` object can be a subset of those that pass the `NSWhoseSpecifier` object’s test. This subset is specified by the various sub-element properties of the `NSWhoseSpecifier` object . Consider as an example the specifier `paragraphs where color of third word is blue`. This would be represented by an `NSWhoseSpecifier` object  that uses a test specifier and another object specifier to identify a subset of the objects with the specified property. That is, the specifier’s property is `paragraphs`; the test specifier is an index specifier with property `words` and `index 3`; and the qualifier is a key value qualifier for key `color` and value `[NSColor blueColor]`. The test object specifier (`word at index 3`) is evaluated for each object (paragraph) using that object as the container; the resulting objects (if any) are tested with the qualifier (`color blue`).

`NSWhoseSpecifier` is part of Cocoa’s built-in script handling. You don’t normally subclass it.

## Topics

### Initializing a whose specifier

[`-  initWithContainerClassDescription:containerSpecifier:key:test:`](/documentation/Foundation/NSWhoseSpecifier/init(containerClassDescription:containerSpecifier:key:test:))

Returns an `NSWhoseSpecifier` object initialized with the given attributes.

### Accessing information about a whose specifier

[`endSubelementIdentifier`](/documentation/Foundation/NSWhoseSpecifier/endSubelementIdentifier)

Sets the end sub-element identifier for the specifier to the value of a given sub-element.

[`endSubelementIndex`](/documentation/Foundation/NSWhoseSpecifier/endSubelementIndex)

Sets the index position of the last sub-element within the range of objects being tested that pass the specifier’s test.

[`startSubelementIdentifier`](/documentation/Foundation/NSWhoseSpecifier/startSubelementIdentifier)

Returns the start sub-element identifier for the receiver.

[`startSubelementIndex`](/documentation/Foundation/NSWhoseSpecifier/startSubelementIndex)

Returns the index position of the first sub-element within the range of objects being tested that pass the receiver’s test.

[`test`](/documentation/Foundation/NSWhoseSpecifier/test)

Returns the test object encapsulated by the receiver.

### Constants

[`SubelementIdentifier`](/documentation/Foundation/NSWhoseSpecifier/SubelementIdentifier)

`NSWhoseSpecifier` uses these constants to specify sub-elements within the collection of objects being tested that pass the specifier’s test.

## Relationships

### Inherits From

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

### Conforms To

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

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

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

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

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

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

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

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

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

---

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)