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
3 answers

SwiftUI Combine Data Flow

Been away from the swift-ing for a good 3 years now. Getting back into it now and trying to learn Combine and SwiftUI. Making a test Workout app. Add an exercise, record reps and weights for 3 sets. Save data. I'm having issues moving some data…
Pavel B.
  • 1
  • 1
0
votes
2 answers

Listening to updates in an Array of Objects in Swift

I'm working on a project where I need to listen to any changes in an array of objects. By changes I refer: Add/Remove element in the array Any change in the existing array elements Here is the sample code, enum DownloadState { case queued …
PGDev
  • 23,751
  • 6
  • 34
  • 88
0
votes
1 answer

What's the best way to listen to NSAttributedString attribute changes in Combine?

I have a model that is a group of NSMutableAttributedStrings. Well currently it's a wrapper of a MyString class. Each string manages it's own attributes/state. typealias NSAttrStringAttr = [NSAttributedString.Key: Any] typealias MyStringAttribute =…
Peter R
  • 3,185
  • 23
  • 43
0
votes
2 answers

Data flow with Combine in SwiftUI

Hello I had spend over 10 hour to implement Combine framework but can't clear understanding how to link Publisher and Subscriber. In example I just wanna call setTheme funk from Theme class and automatically update game variable in Game class. I…
Nizami
  • 728
  • 1
  • 6
  • 24
0
votes
0 answers

Is it possible to get the result of the first Task in a group to finish and cancel the rest?

I'm working on a word game, and I'm trying to dynamically generate puzzles based on arrays of random letters from a weighted set. What I have below works, but the word list I'm using is fairly limited (about 2300 words), and it takes forever. My…
forgot
  • 2,160
  • 2
  • 19
  • 20
0
votes
1 answer

Combine publisher for changes to UIStackView's arrangedSubviews array

I have a basic view controller subclass which contains a UIStackView and a UIButton. I want to run some code each time a view is added or removed from the stack view's arrangedSubviews array using Combine. Here's is my failed attempt to do…
alobaili
  • 761
  • 9
  • 23
0
votes
1 answer

Toggle a Boolean in a Binding object doesn't update UI

Hello i have an issue with the refresh of my view when i toggle a boolean. Here is the code class MyItem: Identifiable { @Published var isActive: Bool } struct myView: View { @Binding var item: MyItem var body: some View { HStack { …
0
votes
1 answer

How do I bind/assign one PassthroughSubject to another?

I am coming from RxSwift and usually end up binding PublishSubjects together. I see that in Combine PassthroughSubject is the equivalent. I have tried the following code: let passthroughSubject1 = PassthroughSubject() let…
Kex
  • 8,023
  • 9
  • 56
  • 129
0
votes
1 answer

Swift Combine Return Int From URLSession.shared.dataTaskPublisher

I have the following code that makes an API call, receives data and assigns it to Core Data managed objects. This works well, and updates my data. func importUsers(url: URL) { URLSession.shared.dataTaskPublisher(for: url) .map(\.data) …
Yrb
  • 8,103
  • 2
  • 14
  • 44
0
votes
1 answer

Why scenePhase value is .background while the app is in the foreground?

I want to do something from the model file when the app goes to the background, like stop the timer or something else. But when I run the app and check for the scenePhase value it returns .background while the app is in the foreground. import…
Fawzi Rifai
  • 533
  • 1
  • 4
  • 12
0
votes
1 answer

CurrentValueSubject send(value) doesn't trigger receiveValue

I have a CurrentValueSubject to hold data received from Firebase fetch request. final class CardRepository: ObservableObject { private let store = Firestore.firestore() var resultSubject = CurrentValueSubject<[Card], Error>([]) init()…
bao le
  • 927
  • 2
  • 7
  • 12
0
votes
1 answer

How to convert AnyPublisher, Never> to AnyPublisher

DataResponse is the object of Alamofire. It returns Decodable object and Error in success itself in . Requirement is to pass on received Decodable object and Error separately. Is it feasible to transform AnyPublisher, Never>…
Kiran Jasvanee
  • 6,362
  • 1
  • 36
  • 52
0
votes
0 answers

How to call methods on StateObject changes

I have a @EnvironmentObject for my Model where I handle the database changes and view state changes. Then I have a View where I initialise a @StateObject for my ApplePayModel, this handles actual payment transactions. Currently I have the…
RileyDev
  • 2,950
  • 3
  • 26
  • 61
0
votes
1 answer

Transforming Alamofire response when using Codable and Combine

I want to use Alamofire to query my backend, encode the response using Alamofire's built-in Codable parsing and then publish an extract from the resulting Struct to be consumed by the caller of my API class. Say I have some JSON data from my…
Robin Macharg
  • 1,468
  • 14
  • 22
0
votes
1 answer

Are Tasks automatically cancelled upon return/completion in Swift?

I am a little uncertain about task cancellation in swift. My question is: If a task reaches its return line (in this example, Line 4), does this mean it will be automatically canceled? (and thus free up memory + any used thread(s) previously…
Josh Arnold
  • 249
  • 4
  • 8