Created
August 25, 2020 16:54
-
-
Save mazz/1fb52e3535e5ba799415e9ff410f1f93 to your computer and use it in GitHub Desktop.
simple combine example
This file contains 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
// | |
// 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. | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
o/p: