Why is sink never called in my combine pipeline?
dataTaskPublisher(for: urlRequest)
will send values asynchronously. When program execution leaves your current scope, there are no more references to your pipeline and ARC destroys your pipeline before the network request has completed.
Your pipeline returns a Cancellable. Either assign that Cancellable directly to an instance variable or add the store(in:)
operator to your pipeline.
Also worth mentioning is that if you mess around with Combine pipelines in an Xcode playground, your pipelines may live longer than you'd expect because the Playground tries to be smart about holding on to references for the sake of making experimentation easier. See this answer for an async example you can run in a playground, even though it applies neither of the fixes I mentioned.
.sink method from Combine not working on iOS 13.3
This might be due to fixed releasing of cancelable (just an assumption). Try the following
var cancellables = Set<AnyCancellable>()
init() {
$segmentedSelected
.debounce(for: .seconds(0.1), scheduler: DispatchQueue.main)
.sink(receiveValue: self.segmentedChanged(indexValue:))
.store(in: &cancellables)
}
Related Topics
Swift - How to Mutate a Struct Object When Iterating Over It
What Are the Rules for Spaces in Swift
How to Make the Scroll of a Tableview Inside Scrollview Behave Naturally
How to Determine the Type of a Variable in Swift
Dynamic Row Hight Containing Texteditor Inside a List in Swiftui
How to Do If Pattern Matching with Multiple Cases
What Causes 'Constant Captured by a Closure Before Being Initialized' Error
How to Return Value from Async Block in Swift
Create a Paginated PDF-MAC Os X
Swift - Custom Setter on Property
Reading Data into a Struct in Swift
Lesser Than or Greater Than in Swift Switch Statement
Delete Data from Coredata Swift
Draw on a PDF Using Swift on MACos
Variable 'Xxx' Was Never Mutated, Consider Changing to 'Let'