I created a small gist on github.com to show you how to create your own custom errors in swift including localized descriptions. The script is mostly self describing. Feel free to leave a comment if not.
// sepcifiy your errors
enum MyCustomError : Error {
case customError
case missingProperty
var localizedDescription: String {
switch self {
case .urlCouldNotBeCreated:
return NSLocalizedString("MyCustomErrorCcustomError", value: "a localized error message", comment: "")
case .missingProperty:
return NSLocalizedString("MyCustomErrorMissingProperty", value: "Missing coordinates", comment: "")
}
}
}
// use your error
func demo() throws {
throw MyCustomError.customError
}
// catch your error
do {
try demo()
} catch let error as MyCustomError {
print(error.localizedDescription)
}