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

# insertColor(_:key:at:)

Inserts the specified color at the specified location in the color list.

```
func insertColor(_ color: NSColor, key: NSColor.Name, at loc: Int)
```

## Parameters

`color`

The color to add to the color list.

`key`

The key with which to associate the color.

`loc`

The location in the color list at which to place the specified color. Locations are numbered starting with 0.

## Discussion

If the list already contains a color with the same key at a different location, it’s removed from the old location. This method posts [`didChangeNotification`](/documentation/AppKit/NSColorList/didChangeNotification) to the default notification center. It raises `NSColorListNotEditableException` if the color list isn’t editable.

---

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)