Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gokselkoksal/79f1ac0958bc4eaa05c739d3daa9f26e to your computer and use it in GitHub Desktop.
Save gokselkoksal/79f1ac0958bc4eaa05c739d3daa9f26e to your computer and use it in GitHub Desktop.
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