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 | |
extension UIRefreshControl { | |
private static var beginRefreshingAssociatedKey = "BeginRefreshingPublisher" | |
private typealias BeginRefreshingPublisher = PassthroughSubject<Void, Never> | |
private var internalBeginRefreshingPublisher: BeginRefreshingPublisher { | |
var publisher = objc_getAssociatedObject( |
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
var cancellables = Set<AnyCancellable>() | |
func setupPipelines() { | |
let searchPublisher = searchBar.searchTextField.textPublisher | |
.prepend(searchBar.text!) | |
.eraseToAnyPublisher() | |
let sparsedSearchPublisher = searchPublisher | |
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main) | |
.eraseToAnyPublisher() |
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 | |
extension UITextField { | |
var textPublisher: AnyPublisher<String?, Never> { | |
NotificationCenter.default | |
.publisher( | |
for: UITextField.textDidChangeNotification, | |
object: self) | |
.map(\.object) |
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 Combine | |
let measurements = PassthroughSubject<Int, Never>() | |
let diagramDataSource = measurements | |
.share(replay: 3) | |
let subscriber1 = diagramDataSource | |
.sink( | |
receiveCompletion: { completion in |
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 Combine | |
final class ShareReplay<Upstream: Publisher>: Publisher { | |
typealias Output = Upstream.Output | |
typealias Failure = Upstream.Failure | |
var recording = Record<Output, Failure>.Recording() | |
var upstreamShare: AnyPublisher<Output, Failure> | |
let bufferCapacity: Int | |
var subscription: AnyCancellable? |
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 Combine | |
import XCombine | |
let events = PassthroughSubject<String, Never>() | |
let numbers = (0...).publisher | |
let subscriber = events | |
.x.zip(numbers) | |
.map { ($1, $0) } // swap |
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 Combine | |
let events = PassthroughSubject<String, Never>() | |
let subscriber = events | |
.scan(nil) { a, v in | |
return (a == nil ? 0 : a!.0 + 1, v) | |
} | |
.compactMap { $0 } | |
.sink(receiveValue: { value in |
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 Combine | |
let events = PassthroughSubject<String, Never>() | |
let numbers = (0...).publisher | |
.print("numbers") | |
let subscriber = events | |
.print("events") | |
.zip(numbers) |
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 Combine | |
let events = PassthroughSubject<String, Never>() | |
let numbers = (0...).publisher | |
.print("numbers") | |
let subscriber = events | |
.print("events") | |
.zip(numbers) |
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 Combine | |
let events = PassthroughSubject<String, Never>() | |
let numbers = (0..<100).publisher | |
let subscriber = events | |
.zip(numbers) | |
.map { ($1, $0) } // swap | |
.sink( |