<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSError/setUserInfoValueProvider(forDomain:provider:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSError(cm)setUserInfoValueProviderForDomain:provider:"
  },
  "title" : "setUserInfoValueProvider(forDomain:provider:)"
}
-->

# setUserInfoValueProvider(forDomain:provider:)

Specifies a block to call when the corresponding property is not present in the user info dictionary.

```
class func setUserInfoValueProvider(forDomain errorDomain: String, provider: (@Sendable (any Error, String) -> Any?)? = nil)
```

## Parameters

`errorDomain`

The error domain of the provider.

`provider`

A block to be executed synchronously at the time a corresponding property is accessed.

- err: The error object that is being accessed.
- userInfoKey: The user info key corresponding to the accessed property.

## Discussion

This method specifies a block that is called from the implementations of [`localizedDescription`](/documentation/Foundation/NSError/localizedDescription), [`localizedFailureReason`](/documentation/Foundation/NSError/localizedFailureReason), [`localizedRecoverySuggestion`](/documentation/Foundation/NSError/localizedRecoverySuggestion), [`localizedRecoveryOptions`](/documentation/Foundation/NSError/localizedRecoveryOptions), [`recoveryAttempter`](/documentation/Foundation/NSError/recoveryAttempter), and [`helpAnchor`](/documentation/Foundation/NSError/helpAnchor) when the underlying value for any of those properties is not present in the [`userInfo`](/documentation/Foundation/NSError/userInfo) dictionary of NSError instances with the specified domain.

A user info provider is optional, and allows localization and formatting of error messages to be done lazily, rather than populating the [`userInfo`](/documentation/Foundation/NSError/userInfo) at the time of creation. It is expected that only the “owner” of an [`NSError`](/documentation/Foundation/NSError) domain specifies the provider for the domain, and that this is done at most once. This method is not meant for consumers of errors to customize the [`userInfo`](/documentation/Foundation/NSError/userInfo) entries, and should not be used to customize the behaviors of error domains provided by the system.

The keys of a provider’s [`userInfo`](/documentation/Foundation/NSError/userInfo) dictionary correspond to the queried property, such as [`NSLocalizedDescriptionKey`](/documentation/Foundation/NSLocalizedDescriptionKey) for the [`localizedDescription`](/documentation/Foundation/NSError/localizedDescription) property. The provider should return `nil` for any keys that it is unable to provide, as well as any keys it does not recognize (since the list of error keys may be extended in future releases). If an appropriate result for the requested key cannot be provided, return `nil` rather than choosing to manufacture a generic fallback response.

The provider block is executed synchronously at the time when a corresponding property is accessed. The results are not cached.

---

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)