Questions tagged [combine]

Combine is Apple's declarative Swift API for processing values over time. It is based on the Reactive Streams semantics. Use this tag for questions about the Combine framework.

Combine is a closed-source Apple framework based on semantics defined by the Reactive Streams initiative.

Combine defines a declarative API in the Swift programming language for processing values over time. Unlike other Swift reactive frameworks such as RxSwift and ReactiveSwift, Combine includes support for back-pressure and flow control at a fundamental level.

Apple first revealed Combine at WWDC on June 3, 2019 and made it available in the first beta release of Xcode 11.

Combine is part of the following SDKs:

  • macOS 10.15 (Catalina) and later,
  • iOS 13 and later,
  • tvOS 13 and later,
  • watchOS 6 and later.
1968 questions
0
votes
1 answer

How to have Combine subscriber finish upon receiving specific value

I'm trying to use a Combine subscriber to wait for a specific value from a publisher, which seems easy enough if I handle the values in sink(receiveValue:), but I want to convert the publisher to another publisher that just finishes when the…
RL2000
  • 913
  • 10
  • 20
0
votes
0 answers

Apple Combine: How to tell that a subscriber stopped listening to a publisher

I am trying to perform a cleanup after the subscriber has stopped listening to the publisher. My approach was to register for a closing and deallocation event, but I am struggling to figure out when a subscriber has stopped listening for events…
maticzav
  • 880
  • 9
  • 17
0
votes
1 answer

How to call published property without updating value

In SwiftUI, combine I have a published property. @Published var name: String And when the name is updated it calls an app and set other values. $name ... ... .assign(to: &$something) Now I want to call this without updating the name at some case
arun siva
  • 809
  • 1
  • 7
  • 18
0
votes
1 answer

How to convert Binding array value to Binding<[type]> instead of [Binding] in Swift/SwiftUI

I have trouble with getting Binding values in correct format out of dataModel. The XCode error I am getting is "Cannot convert value of type '[Binding]' to expected argument type 'Binding<[String]>'" public final class…
Adam Linke
  • 81
  • 6
0
votes
1 answer

How do I observe changes on an array with Combine framework?

How can I observe changes on an array with Combine framework but without SwiftUI? Basically, I want this sink block to get called when an element is added or removed. import Combine var list = ["A", "B", "C"] list.publisher .collect() .sink…
taichino
  • 1,135
  • 1
  • 15
  • 30
0
votes
1 answer

How to merge Publisher one by one in Swift Combine

The following codes will output 1,2,3,4,5, then 300,400, 500 Is there a way to emit one by one like 1, 300, 2, 400, 3, 500, 4, 5 print("\n* Demonstrating Merge") let publisher1 = [1,2,3,4,5].publisher let publisher2 = [300,400,500].publisher let…
LiangWang
  • 8,038
  • 8
  • 41
  • 54
0
votes
2 answers

An Ordered chain of Publishers

I have two Publishers, I want to feed the second one with the result of first one, I could do what I wanted by calling the second one nested into the first one, it works but it does not feel good to look at, is there a better way to do it? the first…
Maysam
  • 7,246
  • 13
  • 68
  • 106
0
votes
0 answers

how to protocol a publisher for SwiftUI

I am refactoring / adding features to some code and encountered a situation where I want to migrate by protocoling the types. Currently I have a data type like this: struct Result { let a: Int let b: Int let c: Int } and an ObservableObject…
Avba
  • 14,822
  • 20
  • 92
  • 192
0
votes
4 answers

Etymology of "sink" in SwiftUI / Combine?

I'm joining development on an existing SwiftUI / Combine iOS project, which is my first exposure to the technology. The names of functions like assign(to:on:) are easy enough to grok, but I'm lost at sink. This function is mentioned in some of the…
pkamb
  • 33,281
  • 23
  • 160
  • 191
0
votes
1 answer

iOS Combine framework @Published doesnt capture post modification values

I noticed that sink is called only once class StorefrontViewModel { @Published var page = 0 @Published var string = "lorem ipsum" private var cancellableBag = Set() init() { let publisher =…
V V
  • 774
  • 1
  • 9
  • 29
0
votes
1 answer

Why does @Published not work in NSManagedObject?

@Published publishes correctly when used in an ObservableObject. But does not seem to publish when used in an NSManagedObject (which conforms to ObservableObject). In the following example when using Data1 the text below the picker is updated. But…
John
  • 964
  • 8
  • 21
0
votes
0 answers

How to update nested structure of a published variable using another api call

I have a published var called spotWallet in my BinanceStore class which conforms to observaleObject. I can create a publisher and subscribe to it. but there is property in my top level struct called balances which is an array of Balance struct. What…
0
votes
0 answers

Can't add constraint to method

I'm trying to create a publisher for CoreData changes. I've implemented Publisher protocol and I was required to implement NSFetchedResultsControllerDelegate in same type (not in extension). Next, I need to implement different…
Alexey
  • 79
  • 7
0
votes
1 answer

Problems with timer and views in SwiftUI

I try to develop an WatchOS app, where the views are feeded by a timer: import SwiftUI import Combine class AcidityTimer: ObservableObject { @Published var num: Int = 0 private var subscription: AnyCancellable? init() { …
PeeWee
  • 11
0
votes
1 answer

How to implement a two-way binding in a ForEach statement with nested views with Swift?

I've implemented a two-way binding in a Foreach statement that seems to work properly: struct ContentView: View { @ObservedObject var dataManager: ContentViewModel var body: some View { ScrollView(.horizontal, showsIndicators:…
Manuel Zompetta
  • 394
  • 4
  • 17