---
title: "setColor(_:forKey:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nscolorlist/setcolor(_:forkey:)"
---

# setColor(_:forKey:)

Associates the specified color object with the specified key.

## Declaration

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

## Parameters

- `color`: The color to associate with the given key.
- `key`: The key.

## Discussion

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:).

## See Also

### Managing Colors By Key

- [allKeys](appkit/nscolorlist/allkeys.md)
- [color(withKey:)](appkit/nscolorlist/color(withkey:).md)
- [insertColor(_:key:at:)](appkit/nscolorlist/insertcolor(_:key:at:).md)
- [removeColor(withKey:)](appkit/nscolorlist/removecolor(withkey:).md)
