gpt4 book ai didi

macos - 哪些字段 -[NSResponder PresentError :] show?

转载 作者:行者123 更新时间:2023-12-03 16:35:34 24 4
gpt4 key购买 nike

有没有关于-[NSResponder presentError:]如何的文档方法有效吗?我正在尝试在我的库中创建 NSError 实例,其 userInfo 值向用户显示尽可能多的有用信息。我现在过得很艰难。

我一开始只使用NSLocalizedFailureReasonErrorKey。看到它分配了生成的 NSAlertmessageText 属性(粗体字体,最上面的标签),我接下来尝试添加 NSLocalizedDescriptionKey,我认为然后将填写 informativeText 属性,以获取其下的非粗体解释。我还添加了 NSURLErrorKey,因为这个库处理文件,它会很有帮助。

生成的 NSAlert 根本不显示原始 NSLocalizedFailureReasonErrorKey 值,新的 NSLocalizedDescriptionKey 现在成为 messageText。它也根本不公开 NSURLErrorKey

我唯一的选择是编写自己的错误表示方法和特殊情况的该库的域吗?

最佳答案

NSError 键如何与 presentError: 交互记录在错误处理编程指南的 Localized Error Information 下。 .

它包含一个图表,详细说明了什么到哪里。正如文档所述:

Failure reason

A brief sentence that explains the reason why the error occurred. It is typically part of the error description. Methods such as presentError: do not automatically display the failure reason because it is already included in the error description. The failure reason is for clients that only want to display the reason for the failure.

如果您想在呈现之前重新排列 NSError 对象中的字段,最好通过重写 willPresentError: 以返回调整后的错误对象来完成。

对于像 NSURLErrorKey 这样的字段,如果您想显示它,您应该将其包含在 NSLocalizedDescriptionKeyNSLocalizedRecoverySuggestionErrorKey 中。虽然它被称为“恢复建议”,但文档明确表示它可以“用作补充错误描述和失败原因的纯粹信息性消息。”

关于macos - 哪些字段 -[NSResponder PresentError :] show?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28680300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com