Skip to content

Instantly share code, notes, and snippets.

@mludi
Created October 4, 2017 10:42
Show Gist options
  • Save mludi/0010c3a07e5e5a2da0f4527ae7d148f7 to your computer and use it in GitHub Desktop.
Save mludi/0010c3a07e5e5a2da0f4527ae7d148f7 to your computer and use it in GitHub Desktop.
Show usage of Swift enum
import UIKit
enum Style: String {
case light, dark
}
class ViewController: UIViewController {
let style: Style
init(style: Style) {
self.style = style
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
self.title = self.style.rawValue
view.backgroundColor = {
style in
switch style {
case .light:
return UIColor.white
case .dark:
return UIColor.darkGray
}
}(self.style)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle : UIStatusBarStyle {
switch self.style {
case .light:
return .lightContent
case .dark:
return .default
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment