<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSImage/setName(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSImage(im)setName:"
  },
  "title" : "setName(_:)"
}
-->

# setName(_:)

Registers the image object under the specified name.

```
func setName(_ string: NSImage.Name?) -> Bool
```

## Parameters

`string`

The name to associate with the receiver. Specify `nil` if you want to remove the image from the image cache.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the receiver was successfully registered with the given name; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

If the receiver is already registered under a different name, this method unregisters the other name. If a different image is already registered under the name specified in `aString`, this method does nothing and returns <doc://com.apple.documentation/documentation/Swift/false>.

When naming an image using this method, it is convention not to include filename extensions in the names you specify. That way, you can easily distinguish between images you have named explicitly and those you want to load from the app’s bundle. For information about the rules used to search for images, and for information about the ownership policy of named images, see the [`init(named:)`](/documentation/AppKit/NSImage/init(named:)) method.

---

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)