Last active
March 2, 2018 10:46
-
-
Save gokselkoksal/79f1ac0958bc4eaa05c739d3daa9f26e to your computer and use it in GitHub Desktop.
Using Channels #1
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
enum Theme: String { | |
case light, dark | |
} | |
protocol UserSettingsDelegate { | |
func themeDidChange(_ theme: Theme) | |
} | |
class UserSettings { | |
var delegate: UserSettingsDelegate? | |
var theme: Theme = .light { | |
didSet { | |
delegate?.themeDidChange(theme) | |
} | |
} | |
init() { } | |
} |
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
class HomeViewController: UIViewController { | |
private lazy var userSettings: UserSettings = { | |
let settings = UserSettings() | |
settings.delegate = self | |
return settings | |
}() | |
func didTapOnSettings() { | |
let settingsVC = SettingsViewController(userSettings: userSettings) | |
present(settingsVC, animated: true) | |
} | |
} | |
extension HomeViewController: UserSettingsDelegate { | |
func themeDidChange(_ theme: Theme) { | |
// Apply theme here. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment