什么是 NSLocalizedFailureErrorKey ?
What is `NSLocalizedFailureErrorKey` for?
在文档齐全的字符串 NSLocalizedDescriptionKey
、NSLocalizedFailureReasonErrorKey
、NSLocalizedRecoveryOptionsErrorKey
和 NSLocalizedRecoverySuggestionErrorKey
中,还有 NSLocalizedFailureErrorKey
,它缺少任何类型的描述在文档中。它有什么用?
来自header:
FOUNDATION_EXPORT NSErrorUserInfoKey const NSLocalizedFailureErrorKey API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0));
// NSString
A complete sentence (or more) describing what failed. Setting a value for this key in userInfo dictionary of errors received from framework APIs is a good way to customize and fine tune the localizedDescription of an NSError.
As an example, for Foundation error code NSFileWriteOutOfSpaceError, setting the value of this key to "The image library could not be saved." will allow the localizedDescription of the error to come out as "The image library could not be saved. The volume Macintosh HD is out of space." rather than the default (say) “You can't save the file ImgDatabaseV2 because the volume Macintosh HD is out of space."
在文档齐全的字符串 NSLocalizedDescriptionKey
、NSLocalizedFailureReasonErrorKey
、NSLocalizedRecoveryOptionsErrorKey
和 NSLocalizedRecoverySuggestionErrorKey
中,还有 NSLocalizedFailureErrorKey
,它缺少任何类型的描述在文档中。它有什么用?
来自header:
FOUNDATION_EXPORT NSErrorUserInfoKey const NSLocalizedFailureErrorKey API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0)); // NSString
A complete sentence (or more) describing what failed. Setting a value for this key in userInfo dictionary of errors received from framework APIs is a good way to customize and fine tune the localizedDescription of an NSError.
As an example, for Foundation error code NSFileWriteOutOfSpaceError, setting the value of this key to "The image library could not be saved." will allow the localizedDescription of the error to come out as "The image library could not be saved. The volume Macintosh HD is out of space." rather than the default (say) “You can't save the file ImgDatabaseV2 because the volume Macintosh HD is out of space."