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

Significance of order of statements when writing Combine code?

If i run the code below: import Foundation import Combine import UIKit let textField = UITextField() let array = ["1", "2", "3", "4", "5", "6", "7"] let publisher = array.publisher //Statement 1 textField.publisher(for: \.text).sink{…
Anton Unt
  • 1,835
  • 1
  • 21
  • 47
0
votes
1 answer

SwiftUI Combine How to update textfield

I'm learning Combine and how it can update a value using publishers. Currently I have created a variable that updates itself when validation fails. var nameError: AnyPublisher { $name .dropFirst() .debounce(for:…
Warve
  • 481
  • 1
  • 8
  • 22
0
votes
1 answer

TabView freezes when navigating back to initial tab

I have my ContentView with 2 tabs. struct ContentView: View { var formViewModel = ViewModel() var body: some View { TabView { HomeTab() .environmentObject(formViewModel) .tabItem { …
Fitzgerald Afful
  • 123
  • 1
  • 15
0
votes
1 answer

How to write auto-toggle Publisher operator?

because of a requirement to auto remove Text after its appearance in 2 seconds, I want to write this operator but still cannot figure out the best way to implement. We can put a timespan parameter and get a new stream, here are two interfaces need…
Quang Hà
  • 4,613
  • 3
  • 24
  • 40
0
votes
0 answers

Touch events seemingly not registering at top of screen

I'm seeing very strange behavior within a view. Here's my layout: struct EventDetailViewContainer: View { let eventID: EventRecord.ID @State var event: EventRecord = EventRecord(keyResults: [], text: "", achievesKR: false) …
sak
  • 2,612
  • 24
  • 55
0
votes
1 answer

Problem enabling and focusing a text field at the same time

So I am working on a view where I want to have editable text which is only made editable via a button press. So basically, when pressing the "edit" button, a text field should be made editable, and the focus should be sent to the text field. Here's…
sak
  • 2,612
  • 24
  • 55
0
votes
0 answers

Is there a way to pass a constant as a binding in SwiftUI?

So let's say I have a view like this: struct MyView { @Binding var inEditMode: Bool ... } In some cases, I want this view to be able to swap in and out of edit mode, but in other cases, I only want it to be read-only. Now I can avhieve this…
sak
  • 2,612
  • 24
  • 55
0
votes
1 answer

Alamofire with Swift Combine

I'm trying to implement Combine framework with Alamofire. But I have problems with generics, can you help me improving my code. So, my APIRouter class: import Alamofire import Foundation public protocol APIConfiguration: URLRequestConvertible { …
Maksim
  • 11
  • 1
  • 5
0
votes
1 answer

SwiftUI parent viewModel containing a nested array of observed objects does not update

(You can skip this part and just look at the code.) I'm creating a complicated form. The form creates, say, a Post object, but I want to be able to create several Comment objects at the same time. So I have a Post form and a Comment form. In my Post…
aspear
  • 78
  • 9
0
votes
1 answer

onReceive callback not executing

So I am working on a view in SwiftUI which will update its state when an event is published. The view looks like this: struct MyView: View { @EnvironmentObject var dataSource: DataSource @State var data: [Model] = [] func…
sak
  • 2,612
  • 24
  • 55
0
votes
1 answer

How to Implement API for both Success and Failure Response with Combine Swift

EDIT: I am trying my level best to make my question simpler, here what I am trying to get a solution for is, I have an API and if my data is valid the API will give the correct response, for which I need to decode with the respective struct in…
0
votes
1 answer

Combine: Chain requests with dependency, keep both responses

I'm trying to wrap my head around this call in Combine. I have two models and calls. One is an array of place data, the second an array for the OpenWeather response. What I need is to pass the latitude and longitude from my first call response into…
deverror
  • 3
  • 2
0
votes
0 answers

SwiftUI: NavigationLink which performs a function first and then dynamically navigates

I have a scenario whereby I have a list of items which all have NavigationLinks embedded. However, the destination of that link should vary depending on the item selected. The added complication though is that the value which I need to check will…
DevB1
  • 1,235
  • 3
  • 17
  • 43
0
votes
2 answers

How can I load state from en EnvironmentObject in SwiftUI?

So I am working on a view where I want to load state from an EnvironmentObject which acts something like a database. I would like to achieve something like this: class MyDB: ObservableObject { func getName(_ id: RecordID) -> String { ... } …
sak
  • 2,612
  • 24
  • 55
0
votes
1 answer

debounce with a flush switch

I want to debounce a stream of values, and add a flush signal to it. When the flush signal comes, debounce should immediately emit its last received value and clear its buffer. If there is no value in debounce's buffer, the flush signal does…
Jack Guo
  • 3,959
  • 8
  • 39
  • 60