Skip to content

Instantly share code, notes, and snippets.

@meyusufdemirci
Created April 12, 2022 14:09
Show Gist options
  • Save meyusufdemirci/5665c9644f8bb088184576e279d194f1 to your computer and use it in GitHub Desktop.
Save meyusufdemirci/5665c9644f8bb088184576e279d194f1 to your computer and use it in GitHub Desktop.
Error Handling Article
enum MainError: Error {
case general
case unknownError
var userFriendlyDescription: String {
"MainError.\(self)".localizeSafely(safe: "MainError.general".localized)
}
}
extension String {
var localized: String {
NSLocalizedString(self, comment: "")
}
func localizeSafely(safe: String) -> String {
let localizedValue = self.localized
return localizedValue == self ? safe : localizedValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment