Answer by Abuzeid for How to provide a localized description with an Error...
enum NetworkError: LocalizedError { case noConnection public var description: String { ///You can switch self here if you have multiple cases. return "No internet connection" } // You need to implement...
View ArticleAnswer by Rico Nguyen for How to provide a localized description with an...
This one worked for me:NSError(domain: "com.your", code: 0, userInfo: [NSLocalizedDescriptionKey: "Error description"])
View ArticleAnswer by Zafer Sevik for How to provide a localized description with an...
Using a struct can be an alternative. A little bit elegance with static localization: import Foundationstruct MyError: LocalizedError, Equatable { private var description: String! init(description:...
View ArticleAnswer by Vitalii Gozhenko for How to provide a localized description with an...
Here is more elegant solution: enum ApiError: String, LocalizedError { case invalidCredentials = "Invalid credentials" case noConnection = "No connection" var localizedDescription: String { return...
View ArticleAnswer by matt for How to provide a localized description with an Error type...
There are now two Error-adopting protocols that your error type can adopt in order to provide additional information to Objective-C — LocalizedError and CustomNSError. Here's an example error that...
View ArticleAnswer by Reza Shirazian for How to provide a localized description with an...
I would also add, if your error has parameters like thisenum NetworkError: LocalizedError { case responseStatusError(status: Int, message: String)}you can call these parameters in your localized...
View ArticleAnswer by Martin R for How to provide a localized description with an Error...
As described in the Xcode 8 beta 6 release notes,Swift-defined error types can provide localized error descriptions by adopting the new LocalizedError protocol.In your case:public enum MyError: Error {...
View ArticleHow to provide a localized description with an Error type in Swift?
I am defining a custom error type with Swift 3 syntax and I want to provide a user-friendly description of the error which is returned by the localizedDescription property of the Error object. How can...
View Article