简体   繁体   English

如何访问错误的非本地化描述?

[英]How to access non-localized description of Error?

It seems that the Error type in Swift provides only one property, localizedDescription . 似乎Swift中的Error类型只提供了一个属性localizedDescription My app will be running on machines set to other languages than English. 我的应用程序将在设置为英语以外的其他语言的计算机上运行。 I would like to write error reports (for my perusal, not the user's) in English: I need the non-localized description of the error. 我想用英文写错误报告(供我细读,而不是用户):我需要错误的非本地化描述。 How can I get it? 我怎么才能得到它?

What I did to solve this issue is create a string using the error's domain and code. 我为解决这个问题所做的是使用错误的域和代码创建一个字符串。 Something like: 就像是:

extension Error {
    var logString: String {
        return (self as NSError).code + ":" + (self as NSError).domain
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM