Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Channels #1
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() { }
}
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