localizedDescription
localizedDescription is a read-only property used in Apple’s Foundation frameworks to provide a user-presentable, localized text describing an error. It is most commonly associated with NSError in Objective-C and is available to Swift errors through bridging to NSError. The value is intended for display to end users and is derived from the error’s userInfo dictionary, using the NSLocalizedDescriptionKey when present; otherwise Foundation supplies a default description based on the error domain and code.
Developers typically set localizedDescription indirectly by providing NSLocalizedDescriptionKey in the NSError userInfo when creating an error,
NSError(domain: "com.example", code: 42, userInfo: [NSLocalizedDescriptionKey: "Could not load data."])
Beyond NSLocalizedDescriptionKey, related keys such as NSLocalizedFailureReasonErrorKey and NSLocalizedRecoverySuggestionErrorKey can supply additional localized strings that explain
Best practices include providing concise, localizable messages and using localization tools (e.g., Localizable.strings) to support multiple
Because localizedDescription is intended for end-user presentation, ensure messages are clear, non-technical when appropriate, and respect