<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/setValue(_:forUndefinedKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime",
      "ObjectiveC"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)setValue:forUndefinedKey:"
  },
  "title" : "setValue(_:forUndefinedKey:)"
}
-->

# setValue(_:forUndefinedKey:)

Invoked by [`setValue(_:forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/setValue(_:forKey:)) when it finds no property for a given key.

```
func setValue(_ value: Any?, forUndefinedKey key: String)
```

## Parameters

`value`

The value for the key identified by `key`.

`key`

A string that is not equal to the name of any of the receiver’s properties.

## Discussion

Subclasses can override this method to handle the request in some other way. The default implementation raises an `NSUndefinedKeyException`.

## See Also

[`func value(forUndefinedKey: String) -> Any?`](/documentation/ObjectiveC/NSObject-swift.class/value(forUndefinedKey:))

Invoked by [`value(forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/value(forKey:)) when it finds no property corresponding to a given key.



---

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)