Created
June 5, 2019 16:27
-
-
Save hermanbanken/cf635644147abd0e330fb6deae758ce4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@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