Login required for access
In order to watch this lesson, you'll need to login to the website.
How to Use Enumerations to Prevent Bugs
YouTube
Enumeration is a very powerful concept when building applications that are bug free. Today, I'll show you how to effectively craft your own enumeration to support our menu component setting names. Hope you enjoy!
!codebreak <div class='filename'>SettingName.swift</div> !codebreak !syntax-highlight enum SettingName: String { case Cancel = "Cancel & Dismiss Completely" case Settings = "Settings" case TermsPrivacy = "Terms & privacy policy" case SendFeedback = "Send Feedback" case Help = "Help" case SwitchAccount = "Switch Account" } !codebreak <div class='filename'>SettingsLauncher.swift</div> !codebreak !syntax-highlight let settings: [Setting] = { let settingsSetting = Setting(name: .Settings, imageName: "settings") let cancelSetting = Setting(name: .Cancel, imageName: "cancel") return [settingsSetting, Setting(name: .TermsPrivacy, imageName: "privacy"), Setting(name: .SendFeedback, imageName: "feedback"), Setting(name: .Help, imageName: "help"), Setting(name: .SwitchAccount, imageName: "switch_account"), cancelSetting] }() func handleDismiss(setting: Setting) { UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .CurveEaseOut, animations: { //... }) { (completed: Bool) in if setting.name != .Cancel { self.homeController?.showControllerForSetting(setting) } } } !codebreak <div class='filename'>SettingCell.swift</div> !codebreak !syntax-highlight var setting: Setting? { didSet { nameLabel.text = setting?.name.rawValue //... } } !codebreak <div class='filename'>HomeController.swift</div> !codebreak !syntax-highlight func showControllerForSetting(setting: Setting) { //... dummySettingsViewController.navigationItem.title = setting.name.rawValue //... }

Comments (3)
6 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
HELP & SUPPORT