简体   繁体   中英

How to access non-localized description of Error?

It seems that the Error type in Swift provides only one property, 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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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