Skip to content

Instantly share code, notes, and snippets.

@derrickshowers
Created January 11, 2020 15:48
Show Gist options
  • Save derrickshowers/adbd6297a7d44388e5c8d47be1a46461 to your computer and use it in GitHub Desktop.
Save derrickshowers/adbd6297a7d44388e5c8d47be1a46461 to your computer and use it in GitHub Desktop.
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