---
title: NSNameSpecifier
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsnamespecifier
---

# NSNameSpecifier

A specifier for an object in a collection (or container) by name.

## Declaration

```swift
class NSNameSpecifier
```

## Overview

Overview As an example, the following script specifies both an application and a window by name. In this script, the named window’s implicitly specified container is the Finder application’s list of open windows. tell application "Finder" -- specifies an application  by name     close window "Reports" -- specifies a window by name end tell This specifier works only for objects that have a name property. You don’t normally subclass NSNameSpecifier. The evaluation of an instance of NSNameSpecifier follows these steps until the specified object is found: If the container implements a method whose selector matches the relevant valueIn<Key>WithName: pattern established by scripting key-value coding, the method is invoked. This method can potentially be very fast, and it may be relatively easy to implement. As is the case when evaluating any script object specifier, the container of the specified object is given a chance to evaluate the object specifier. If the container class implements the indicesOfObjectsByEvaluatingObjectSpecifier method, the method is invoked. This method can potentially be very fast, but it is relatively difficult to implement. An instance of  NSWhoseSpecifier that specifies the first object whose relevant 'pnam' attribute matches the name is synthesized and evaluated. The instance of NSWhoseSpecifier must search through all of the keyed elements in the container, looking for a match. The search is potentially very slow.

## Topics

### Initializing a name specifier

- [init(containerClassDescription:containerSpecifier:key:name:)](foundation/nsnamespecifier/init(containerclassdescription:containerspecifier:key:name:).md)

### Accessing a name specifier

- [name](foundation/nsnamespecifier/name.md)

### Initializers

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

## Relationships

### Inherits From

- [NSScriptObjectSpecifier](foundation/nsscriptobjectspecifier.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)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Object Specifiers

- [NSScriptObjectSpecifier](foundation/nsscriptobjectspecifier.md)
- [NSPropertySpecifier](foundation/nspropertyspecifier.md)
- [NSPositionalSpecifier](foundation/nspositionalspecifier.md)
- [NSRandomSpecifier](foundation/nsrandomspecifier.md)
- [NSRangeSpecifier](foundation/nsrangespecifier.md)
- [NSUniqueIDSpecifier](foundation/nsuniqueidspecifier.md)
- [NSWhoseSpecifier](foundation/nswhosespecifier.md)
- [NSMiddleSpecifier](foundation/nsmiddlespecifier.md)
- [NSIndexSpecifier](foundation/nsindexspecifier.md)
- [NSRelativeSpecifier](foundation/nsrelativespecifier.md)
