How to access non-localized description of Error?
Asked Answered
L

1

17

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?

Laval answered 19/8, 2017 at 19:23 Comment(1)
cast this error to CustomStringConvertible or CustomDebugStringConvertibleChar
V
0

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
    }
}
Vitiate answered 6/9, 2018 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.