Created
January 27, 2019 09:43
-
-
Save bartjacobs/9f57e03dba791835616a776efdcf86ff to your computer and use it in GitHub Desktop.
Using Fatal Errors to Add Clarity and Elegance to Swift - 3
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 Section: Int { | |
case news | |
case profile | |
case settings | |
var title: String { | |
switch self { | |
case .news: return NSLocalizedString("section_news", comment: "news") | |
case .profile: return NSLocalizedString("section_profile", comment: "profile") | |
case .settings: return NSLocalizedString("section_settings", comment: "settings") | |
} | |
} | |
} | |
struct SettingsViewViewModel { | |
func title(for section: Int) -> String { | |
guard let section = Section(rawValue: section) else { fatalError("Unexpected Section") } | |
return section.title | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment