Created
April 12, 2022 14:09
-
-
Save meyusufdemirci/5665c9644f8bb088184576e279d194f1 to your computer and use it in GitHub Desktop.
Error Handling Article
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
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