Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple combine example
//
// ViewController.swift
// combinetest
//
// Created by Michael on 2020-08-25.
// Copyright © 2020 Michael. All rights reserved.
//
import Cocoa
import Combine
class ViewController: NSViewController {
@Published public var slowdown: Bool = false {
didSet {
print("didset slowdown: \(oldValue)")
}
}
private var cancellable: AnyCancellable?
override func viewDidLoad() {
super.viewDidLoad()
slowdown = true
slowdown = false
slowdown = true
slowdown = false
cancellable = $slowdown.sink() { value in
print("slowdown changed: \(value)")
}
print("after sink")
slowdown = true
slowdown = true
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
@mazz
Copy link
Author

mazz commented Aug 25, 2020

o/p:

didset slowdown: false
didset slowdown: true
didset slowdown: false
didset slowdown: true
slowdown changed: false
after sink
slowdown changed: true
didset slowdown: false
slowdown changed: true
didset slowdown: true
2020-08-25 12:52:22.157532-0400 combinetest[1991:35702] Metal API Validation Enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment