Skip to content

Instantly share code, notes, and snippets.

@steveriggins
Created November 16, 2021 02:33
Show Gist options
  • Save steveriggins/809b606017ece133434cd28911657138 to your computer and use it in GitHub Desktop.
Save steveriggins/809b606017ece133434cd28911657138 to your computer and use it in GitHub Desktop.
import Combine
import Foundation
class CombineExampleBase {
@Published var baseValue: Int
init(baseValue: Int) {
self.baseValue = baseValue
}
}
final class CombineExample: CombineExampleBase {
@Published var blurValue: Float
private var cancellables = Set<AnyCancellable>()
init(blurValue: Float) {
self.blurValue = blurValue
super.init(baseValue: 50)
$blurValue
.sink { [weak self] value in
self?.displayBlur(value: value)
}
.store(in: &cancellables)
}
private func displayBlur(value: Float) {
print("BlueValue is: \(value)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment