Created
December 7, 2017 12:50
-
-
Save khawajafarooq/9e5f93710cf8302d6c9d66f920184137 to your computer and use it in GitHub Desktop.
Custom error enum in swift
This file contains hidden or 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
import Foundation | |
enum YearError: Error { | |
case empty | |
case invalidNumber | |
case invalidBirthYear | |
case invalidYear | |
} | |
extension YearError: CustomStringConvertible { | |
var description: String { | |
switch self { | |
case .empty: return "You didn't provide anything" | |
case .invalidNumber: return "You didn't provide a valid number" | |
case .invalidBirthYear: return "You can't be born in the future 🤔" | |
case .invalidYear: return "You didn't provide a valid 4 digits year such as 1989" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment