Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bartjacobs/9f57e03dba791835616a776efdcf86ff to your computer and use it in GitHub Desktop.
Save bartjacobs/9f57e03dba791835616a776efdcf86ff to your computer and use it in GitHub Desktop.
Using Fatal Errors to Add Clarity and Elegance to Swift - 3
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