<!--
{
  "availability" : [
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Bundle/image(forResource:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBundle(im)imageForResource:"
  },
  "title" : "image(forResource:)"
}
-->

# image(forResource:)

Returns an `NSImage` instance associated with the specified name, which can be backed by multiple files representing different resolution versions of the image.

```
func image(forResource name: NSImage.Name) -> NSImage?
```

## Parameters

`name`

The filename of the image resource file. Including a filename extension is optional.

## Return Value

The `NSImage` object associated with the specified name, or `nil` if no file is found.

## Discussion

This method accommodates Apple’s naming conventions for high-resolution versions of the image. For example, if your bundle contains files named `button.png`, `button@2x.png`, and `button.pdf` then `imageForResource:@"button"` returns an `NSImage` object backed by all three files. Each time the `NSImage` object is drawn, it selects the representation best for the drawing context.

Images requested using this method whose name ends in the word `Template` are automatically marked as template images.

This method does not look up images based on <doc://com.apple.documentation/documentation/AppKit/NSImage/setName(_:)> or get named system images. Use <doc://com.apple.documentation/documentation/AppKit/NSImage/init(named:)> for that purpose.

This method does not cache its search results.

## See Also

  <doc://com.apple.documentation/documentation/AppKit/NSImage/init(named:)>



---

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)