Created
January 11, 2020 15:48
-
-
Save derrickshowers/adbd6297a7d44388e5c8d47be1a46461 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import Combine | |
// Just Publishers | |
let publisher = Just("Hello, world!") | |
let subscription = publisher.sink { (theString: String) in | |
print(theString) | |
} | |
// Pass through subjects | |
let passThroughSubject = PassthroughSubject<String, Never>() | |
let passThroughSubscription = passThroughSubject.sink(receiveCompletion: { (completion: Subscribers.Completion<Never>) in | |
print("Completed! \(completion)") | |
}) { (value: String) in | |
print("Value is: \(value)") | |
} | |
passThroughSubject.send("Hello") | |
passThroughSubject.send("My") | |
passThroughSubject.send("Name") | |
passThroughSubject.send("Is") | |
passThroughSubject.send("Derrick") | |
passThroughSubject.send(completion: .finished) | |
// Current value subjects | |
let currentValueSubject = CurrentValueSubject<Int, Never>(1) | |
print(currentValueSubject.value) | |
currentValueSubject.send(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment