Created
December 16, 2017 21:34
-
-
Save cumanzor/668081833cdef324baa1e3743a3154d1 to your computer and use it in GitHub Desktop.
localizable error types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// avoid the whole switch error type set description pattern we were using before (unless custom actions need to be attached or something) | |
// see: https://stackoverflow.com/questions/39176196/how-to-provide-a-localized-description-with-an-error-type-in-swift | |
import Foundation | |
public enum customError:Error{ | |
case NONETWORK | |
case INVALIDJSON | |
case UNEXPECTEDRESPONSE | |
case INVALIDCREDENTIALS | |
case Other(String?) | |
} | |
extension customError: LocalizedError { | |
public var errorDescription: String? { | |
switch self { | |
case .NONETWORK: | |
return NSLocalizedString("No hay conexión al servidor.", comment: "Sin conectividad") | |
case .INVALIDJSON, .UNEXPECTEDRESPONSE: | |
return NSLocalizedString("Respuesta del servidor invalida.", comment: "El servidor ha retornado una respuesta invalida.") | |
case .INVALIDCREDENTIALS: | |
return NSLocalizedString("El usuario o contraseña son incorrectos", comment: "Autorización Invalida") | |
case .Other(let s): | |
return s! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment