Created
October 4, 2017 10:42
-
-
Save mludi/0010c3a07e5e5a2da0f4527ae7d148f7 to your computer and use it in GitHub Desktop.
Show usage of Swift enum
This file contains 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 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