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

# setColor(_:forKey:)

Associates the specified color object with the specified key.

```
func setColor(_ color: NSColor, forKey key: NSColor.Name)
```

## Parameters

`color`

The color to associate with the given key.

`key`

The key.

## Discussion

If the list already contains `key`, this method sets the corresponding color to `color`; otherwise, it inserts `color` at the end of the list by invoking [`insertColor(_:key:at:)`](/documentation/AppKit/NSColorList/insertColor(_:key:at:)).

---

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)