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

# value(forUndefinedKey:)

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

```
func value(forUndefinedKey key: String) -> Any?
```

## Parameters

`key`

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

## Discussion

Subclasses can override this method to return an alternate value for undefined keys. The default implementation raises an `NSUndefinedKeyException`.

## See Also

[`func setValue(Any?, forUndefinedKey: String)`](/documentation/ObjectiveC/NSObject-swift.class/setValue(_:forUndefinedKey:))

Invoked by [`setValue(_:forKey:)`](/documentation/ObjectiveC/NSObject-swift.class/setValue(_:forKey:)) when it finds no property for 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)