Among the well-documented strings NSLocalizedDescriptionKey, NSLocalizedFailureReasonErrorKey, NSLocalizedRecoveryOptionsErrorKey, and NSLocalizedRecoverySuggestionErrorKey there is also NSLocalizedFailureErrorKey, which lacks any kind of description in documentation. What is it for?
What is `NSLocalizedFailureErrorKey` for?
499 Views Asked by Ilias Karim AtThere are 2 best solutions below
On
Let me quote the documentation of -localizedDescription from NSError.h (I only applied some layouting and styling to it):
The primary user-presentable message for the error, for instance for
NSFileReadNoPermissionError:The file "File Name" couldn't be opened
because you don't have permission to view it.This message should ideally indicate what failed and why it failed.
This value either comes from
NSLocalizedDescriptionKey, orNSLocalizedFailureErrorKey+NSLocalizedFailureReasonErrorKey, orNSLocalizedFailureErrorKey.The steps this takes to construct the description include:
Look for
NSLocalizedDescriptionKeyinuserInfo, use value as-is if present.Look for
NSLocalizedFailureErrorKeyinuserInfo. If present, use, combining with value forNSLocalizedFailureReasonErrorKeyif available.Fetch
NSLocalizedDescriptionKeyfromuserInfoValueProvider, use value as-is if present.Fetch
NSLocalizedFailureErrorKeyfromuserInfoValueProvider. If present, use, combining with value forNSLocalizedFailureReasonErrorKeyif available.Look for
NSLocalizedFailureReasonErrorKeyinuserInfoor fromuserInfoValueProvider; combine with generic "Operation failed" message.Last resort localized but barely-presentable string manufactured from domain and code. The result is never nil.
From the header: