Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 8, 2020 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/9a585eaf16a55444ae3eb3556b599d90 to your computer and use it in GitHub Desktop.
Save jasdev/9a585eaf16a55444ae3eb3556b599d90 to your computer and use it in GitHub Desktop.
`.sink`ing instead of `.assign`ing.
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