/sink_instead_of_assign.swift Secret
Last active
April 8, 2020 21:23
Star
You must be signed in to star a gist
`.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