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
6
votes
2 answers

How to refresh view with fetched data - Firestore & SwiftUI

Short: The Images in my view are not updating after the first load. The URL remains the same as the previous loaded view, however the rest of the view that doesn't fetch a URL or data from storage is updated. Full: I have two Views, a ListView and a…
RileyDev
  • 2,950
  • 3
  • 26
  • 61
6
votes
1 answer

Swift Combine - CFString (Storage) memory leak

Im seeing some memory leaks when using the memory graph debugger in xcode. The Backtrace is not linking directly to any of my code, but guessing by the trace its save to assume that its related to combine and some DataTaskPublisher. Next I checked…
KevinP
  • 2,562
  • 1
  • 14
  • 27
6
votes
2 answers

How do you share a data model between a UIKit view controller and a SwiftUI view that it presents?

My data model property is declared in my table view controller, and the SwiftUI view is modally presented. I'd like the presented Form input to manipulate the data model. The resources I've found on data flow are just between SwiftUI views, and the…
Curiosity
  • 544
  • 1
  • 15
  • 29
6
votes
1 answer

How to update SwiftUI view after @AppStorage in a separate struct gets updated

I have a following class: struct PriceFormatter { @AppStorage(UserDefaultsKey.savedCurrency) var savedCurrency: String? let price: Float init(price: Float) { self.price = price } var formatted: String { …
ramzesenok
  • 5,469
  • 4
  • 30
  • 41
6
votes
2 answers

SwiftUI Combine: @Published is only available on properties of classes

I have the following code and Im getting the message error: 'wrappedValue' is unavailable: @Published is only available on properties of classes //* /** Chat Created on 29/07/2020 */ import SwiftUI let lightGreyColor = Color(red: 239.0/255.0,…
Ricardo
  • 7,921
  • 14
  • 64
  • 111
6
votes
1 answer

How does the Throttle publisher work in Swift Combine?

I'm stuck with Throttle publisher. I don't understand the way it picks intervals. Debounce publisher is much easier to understand, it picks an interval after each published value and checks whether new values are posted during the interval or not.…
iWheelBuy
  • 5,470
  • 2
  • 37
  • 71
6
votes
1 answer

how to stop a timer publisher?

I have been playing around a timer publisher for a while in playground. below is my code let timer = Timer .publish(every: 1.0, on: .main, in: .common) .autoconnect() var counter = 0 let subscriber = timer .map({ (date) -> Void in …
elk_cloner
  • 2,049
  • 1
  • 12
  • 13
6
votes
1 answer

Performing side effects on Publisher

I'm trying to perform side effect on Publisher, and I can't find any operator which will allow me to do something like this. To be precise, I'm looking for a concept similar to RxSwift's do(on:). Here's what I'm trying to do. I'm writing a reactive…
cojoj
  • 6,405
  • 4
  • 30
  • 52
6
votes
2 answers

SwiftUI two-way binding to value inside ObservableObject inside enum case

I am trying to observe changes of a bool value contained in an ObservableObject which is a value in an enum case. Here is an example of what I am trying to achieve but with the current approach I receive the error Use of unresolved identifier…
Bogdan
  • 402
  • 2
  • 8
  • 18
6
votes
1 answer

What's the difference between .sink and Subscribers.Sink?

I want to do an asynchronous job with Future. But the below .sink() closures never get called. It seems that the instance of Future was released right after it was called. Future { promise in …
user2848557
  • 823
  • 1
  • 9
  • 11
6
votes
1 answer

Swift Combine: How to handle event and continue stream

I am implementing a library with a Login function using Swift Combine. With the following code, I am already able to login, serialize the response to an object AuthenticationResult, and return a Publisher with a User or ApiError as a result. As part…
StuckOverFlow
  • 851
  • 6
  • 15
6
votes
2 answers

precondition failure: invalid input index when using GeometryReader in SwiftUI starting with iOS 13.4

Yesterday I upgraded XCode and my project to iOS 13.4 and I started to see a lot of failures in around views that use GeometryReaders. The error does not reveal anything besides "precondition failure: invalid input index"
Andrei Matei
  • 1,049
  • 2
  • 10
  • 23
6
votes
2 answers

SwiftUI - propagating change notifications through nested reference types

I'd like to extend ObservableObject behavior in SwiftUI to nested classes, and I'm looking for the proper way to do it. It can be done "manually" with Combine, but I imagine there's a much cleaner way to do it using SwiftUI, and I'm hoping you can…
Anton
  • 2,512
  • 2
  • 20
  • 36
6
votes
2 answers

SwiftUI UIViewRepresentable UITextView Binding

Multiline text input is currently not natively supported in SwiftUI (hopefully this feature is added soon!) so I've been trying to use the combine framework to implement a UITextView from UIKit which does support multiline input, however i've been…
テッド
  • 776
  • 9
  • 21
6
votes
1 answer

Swift Combine custom Publisher: Storing a reference to an array of Subscribers?

I'm trying to write a custom Combine Publisher that will send decibel and timestamps from an AVAudioEngine tap. After going through numerous tutorials and the WWDC videos, I still can't find an example of how a Publisher keeps track of the…
NRitH
  • 13,441
  • 4
  • 41
  • 44