Skip to content

Instantly share code, notes, and snippets.

@hermanbanken
Created June 5, 2019 16:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermanbanken/cf635644147abd0e330fb6deae758ce4 to your computer and use it in GitHub Desktop.
Save hermanbanken/cf635644147abd0e330fb6deae758ce4 to your computer and use it in GitHub Desktop.
@available(iOS 13.0, *)
func exampleCombineKVO () {
let article = Article(title: "Test", body: "Lorum ipsum")
// For a KeyPath 101, see https://www.swiftbysundell.com/posts/the-power-of-key-paths-in-swift
let keypath: ReferenceWritableKeyPath<Article,String> = \.title
// The new Combine stuff:
let sink = Subscribers.Assign(object: article, keyPath: keypath)
let source = Publishers.Future<String, Never> { subscriber in
DispatchQueue.main.async {
subscriber(.success("42"))
}
}
source.subscribe(sink)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment