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

Best way to achieve animation in SwiftUI with a CurrentValueSubject value change

I’m currently building out a new MVVM app in SwiftUI and wanted to see whether there was a cleaner way of assigning a value from a CurrentValueSubject to my ViewModel, whilst still achieving animations? 

 I’m currently leaning toward solution 2…
Liam Bates
  • 21
  • 1
  • 3
0
votes
1 answer

Result of call is unused with Combine

I have this function import Foundation import Combine import Amplify func fetchCurrentAuthSession() -> AnyCancellable { Amplify.Auth.fetchAuthSession().resultPublisher .sink { if case let .failure(authError) = $0 { …
user18365424
0
votes
0 answers

Network request using Combine doesn't execute

I have the following classes that perform a network call - import SwiftUI import Combine struct CoinsView: View { private let coinsViewModel = CoinViewModel() var body: some View { Text("CoinsView").onAppear { …
Alon Shlider
  • 1,187
  • 1
  • 16
  • 46
0
votes
1 answer

In TCA: How to extract from Effect when not in the reducer?

I have the results from a publisher in an Effect<[Int], Error> How do I assign that [Int] to a variable? Although I am able to get the results using this: case .reviewed: return environment.networkQuery.reviewed(pageCount:…
Mozahler
  • 4,958
  • 6
  • 36
  • 56
0
votes
0 answers

Why is my Publisher subscription immediately cancelled when called from a SwiftUI view initializer?

I have created a gravityPublisher (to receive updates in the current gravity vector) and subscribe to it by calling the following function: private func enableGravityDetection(_ gravityEnabled: Bool) { if gravityEnabled { if cancellable…
Mischa
  • 15,816
  • 8
  • 59
  • 117
0
votes
0 answers

SwiftUI @State cannot be modified

public struct FriendlyTextField: View, BeFriend { public let eternalId: String let title: String @Binding var text: String @State var focused: Bool = false @StateObject var speechManager = SpeechManager.shared @StateObject…
0
votes
0 answers

Swift Combine equivalent of reduce where return value is a publisher not a value

What is the most idiomatic way to process a value a given number of times when that value is derived from another publisher and the resultant value is used in the next iteration? If the value didn't come from another publisher I would use…
nacross
  • 2,013
  • 2
  • 25
  • 37
0
votes
0 answers

SwiftUI: How to run a CountdownTimer in background

How make CountdownTimer and how make let elapsed = public var . I want to make the variable constantly decrease life. For example, as in Tamagotchi - You need to constantly feed the animal so that it does not die. This timer should continuously run…
0
votes
2 answers

How to assign nil if network call returns error using Combine

I have a variable with default value. And make a network call to get the value from server. If it returns some error, then I want to make the variable to nil. How can I do this with Future, Promise, Combine? Asynchronous Programming with Futures and…
arun siva
  • 809
  • 1
  • 7
  • 18
0
votes
1 answer

How Do I relogin after getting a 401 back using URLSession and CombineAPI

I'm new to combine and URLSession and I'm trying to find a way to log in after I get a 401 error back. My Set up for the URLSession. APIErrors: enum APIError: Error { case requestFailed case jsonConversionFailure case invalidData case…
0
votes
0 answers

How to load results from Realm cache while loading network results in Swift Combine

I am trying to use Combine to load initial results using cache from Realm and then making a network request but keep running into road blocks. My work in progress code tries to fetch cache then chains the network request. It also tries to catch the…
Rush B
  • 29
  • 1
  • 9
0
votes
1 answer

How do i parse results from a combine publisher

I am new to the combine world and have written a query that returns the results I need correctly. It's multi-step, but basically makes an api call over the network, parses the returned json and creates an array of records I need. let results2:…
Mozahler
  • 4,958
  • 6
  • 36
  • 56
0
votes
2 answers

@Published not emitting update in tests

So I have this problem with a @Published realm result that is not updating in tests. Basically what I am trying to do is, to test if a realm update is causing my ViewModel to update the ui. To do this I am subscribing to the published field. This is…
Artur Hellmann
  • 315
  • 4
  • 21
0
votes
1 answer

How to dynamically update a SwiftUI View with an @Bindable value

I have a SwiftUI ProgressBar View that displays the percentage progress based on a percentage-value you enter as a Bindable parameter. The progress percentage-value is calculated by a ReminderHelper class, which takes two Ints as its parameters,…
fs_tigre
  • 10,650
  • 13
  • 73
  • 146
0
votes
1 answer

How to bind a Float value from a model to a @Binding:Float property in a SwiftUI View

I have a Circular ProgressBar View that takes a @Binding var progress: Float property as its progress value, what I would like to be able to do is pass the var progress: Float value from the Task objects respectably in the List. I tried assigning…
fs_tigre
  • 10,650
  • 13
  • 73
  • 146