Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using Channels #3
enum Theme: String {
case light, dark
class UserSettings {
enum Message {
case didUpdateTheme(Theme)
static let shared = UserSettings()
let channel = Channel<Message>()
var theme: Theme = .light {
didSet {
init() { }
class HomeViewController: UIViewController {
let userSettings = UserSettings.shared
override func viewDidLoad() {
func subscribe() { { (message) in
switch message {
case .didUpdateTheme(let theme):
// Apply theme here.

This comment has been minimized.

Copy link

commented Jul 31, 2018

Hi! Thanks for this.
Can you show how to unsubscribe properly? And how to use the self argument passed into subscribe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.