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

# setIcon(_:forFile:options:)

Sets the icon for the file or directory at the specified path.

```
func setIcon(_ image: NSImage?, forFile fullPath: String, options: NSWorkspace.IconCreationOptions = []) -> Bool
```

## Parameters

`image`

The image to use as the icon for the file or directory.

`fullPath`

The full path of the file or directory.

`options`

The icon representations to generate from the image. You specify this value by combining the appropriate [`NSWorkspace.IconCreationOptions`](/documentation/AppKit/NSWorkspace/IconCreationOptions) constants, using the C bitwise `OR` operator. Specify `0` if you want to generate icons in all available icon representation formats.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the icon was set; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

The `image` can be an arbitrary image, with or without transparency. The method automatically scales this image (as needed) to generate the icon representations. The file or folder must exist and be writable by the user.

This method uses the image to set an icon with a size of 512 pixels by 512 pixels. If you specify the [`exclude10_4ElementsIconCreationOption`](/documentation/AppKit/NSWorkspace/IconCreationOptions/exclude10_4ElementsIconCreationOption) option (not recommended), this method creates an icon that is compatible with the Finder from macOS 10.2 or earlier.

You can safely call this method from any of your app’s threads, but you must call it from only one thread at a time.

---

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)