<!--
{
  "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/NSMapInsertKnownAbsent(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSMapInsertKnownAbsent"
  },
  "title" : "NSMapInsertKnownAbsent(_:_:_:)"
}
-->

# NSMapInsertKnownAbsent(_:_:_:)

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

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

## Discussion

Inserts `key` (which must not be `notAKeyMarker`) and `value` into `table`. Unlike `NSMapInsert`, this function raises `NSInvalidArgumentException` if `table` already includes a key that matches `key`.

`key` is compared with `notAKeyMarker` using pointer comparison; if `key` is identical to `notAKeyMarker`, raises `NSInvalidArgumentException`.

## 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.

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

Inserts a key-value pair into the specified table.



---

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)