<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMapInsert(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSMapInsert"
  },
  "title" : "NSMapInsert(_:_:_:)"
}
-->

# NSMapInsert(_:_:_:)

Inserts a key-value pair into the specified table.

```
func NSMapInsert(_ table: NSMapTable<AnyObject, AnyObject>, _ key: UnsafeRawPointer?, _ value: UnsafeRawPointer?)
```

## Discussion

Inserts `key` and `value` into `table`. If `key` matches a key already in `table`, `value` is retained and the previous value is released, using the `retain` and `release` callback functions that were specified when the table was created. Raises `NSInvalidArgumentException` if `key` is equal to the `notAKeyMarker` field of the table’s [`NSMapTableKeyCallBacks`](/documentation/Foundation/NSMapTableKeyCallBacks) structure.

## See Also

[`NSMapInsertIfAbsent`](/documentation/Foundation/NSMapInsertIfAbsent(_:_:_:))

Inserts a key-value pair into the specified table.

[`NSMapRemove`](/documentation/Foundation/NSMapRemove(_:_:))

Removes a key and corresponding value from the specified table.

[`NSMapInsertKnownAbsent`](/documentation/Foundation/NSMapInsertKnownAbsent(_:_:_:))

Inserts a key-value pair into the specified table if the pair had not been previously added.



---

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)