-
-
Save jasdev/9a585eaf16a55444ae3eb3556b599d90 to your computer and use it in GitHub Desktop.
`.sink`ing instead of `.assign`ing.
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
final class SomeViewModel: ObservableObject { | |
// MARK: - Outputs | |
@Published var someProperty = () | |
// MARK: - Private | |
private var subscriptions = Set<AnyCancellable>() | |
init() { | |
somePublisher | |
.sink(receiveValue: { [weak self] value in /// (1) A lot of ceremony for a simple binding. | |
self?.someProperty = value | |
}) | |
.store(in: &subscriptions) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment