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

SwiftUI CurrentValueSubject Behavior

I'm new in SwiftUI. I'm worked with UIKit and Combine framework building an architecture with ViewModel, UseCases and Repositories. All my architecture is based on the loading states. My loading states are build in this way: /// Equivalent to…
0
votes
0 answers

SwiftUI get sink notification on every update of class ModelObject @Published property

I had class PackageModel: ObservableObject { let id = UUID() @Published var name: String @Published var rateLimit: CGFloat init(name: String, rateLimit: CGFloat) { self.name = name self.rateLimit = rateLimit } } and viewModel class which…
0
votes
0 answers

Conditionally publish changes to a Combine subscriber?

I have an @Published field that dictates whether the user is currently in offline mode. class RequestStatus: ObservableObject { static var shared = RequestStatus() @Published var offlineModeActive: Bool = false private…
Alex Marchant
  • 570
  • 6
  • 21
0
votes
1 answer

Create publisher from blocking callback

I have an old callback API, which has a newValue callback handler emitting one value at a time, and a completion callback, containing an Error or nil, if success. Unfortunately, calling collecting blocks until the API sent all values! func
mydefs
  • 172
  • 10
0
votes
1 answer

Is it possible to subscribe to a view's focus status from a viewModel?

I am currently creating a SwiftUI tvOS UI component that is meant to be autonomous (for possible reuse). We can think of it as a small module. The container view that will inject this component needs to know where the focus is within that component.…
invalidArgument
  • 2,289
  • 4
  • 24
  • 35
0
votes
1 answer

SwiftUI animation - toggled Boolean always ends up as true

I'm trying to create an animation in my app when a particular action happens which will essentially make the background of a given element change colour and back x number of times to create a kind of 'pulse' effect. The application itself is quite…
DevB1
  • 1,235
  • 3
  • 17
  • 43
0
votes
1 answer

SwiftUI Image in App not loading when using Combine

I have been trying to asynchronously load an image in my app using combine. Currently all the other pieces of data are loading fine, but my image seem to be stuck in a progress view. Why? I am not too familiar with how combine works as I have been…
0
votes
1 answer

SwiftUI/iOS 15: fullScreenCover not dismissing with binding on published var

My App uses SwiftUI, targets iOS 15+ and is governed by an ObservableObject, AppState, which serves as the source of truth throughout the app. I use @Published vars to manage the state of overlays (e.g. while loading data) in various places without…
Haensl
  • 343
  • 3
  • 16
0
votes
1 answer

How can i use Combine with @resultbuilder to build a dynamic collectionview list?

I want to use @resultbuilder and Combine to create my own reactive and declarative UICollectionView List in UIKit, similiar to what we get with List {} in SwiftUI. For that, i am using a resultbuilder to create a Snapshot like…
Niklas
  • 1,638
  • 4
  • 19
  • 48
0
votes
2 answers

Custom Combine Publisher wrapper class does not work unless retained

I wrote a Combine Publisher wrapper class for some old code that used delegation. TLDR; Can someone improve how I manage the lifetime of my custom publisher. Preferrable by making it behave like normal publishers, where you can just sink to it and…
Yogurt
  • 2,913
  • 2
  • 32
  • 63
0
votes
1 answer

SwiftUI/Combine: Subscribing to array updates vs element updates

I'm experimenting with SwiftUI and Combine, and wanted to be able to receive notification whenever an array of struct items changes (either changes within items, or changes to the array, i.e. append, remove). I tried the following code, but all I…
Dave Meehan
  • 3,133
  • 1
  • 17
  • 24
0
votes
2 answers

FlatMap with Generic ReturnType using Combine

I'm building a network API. I'm new to Combine and I'm having some troubles with it, I'm trying to chain publish network requests, in this case I'm forming an URLRequest publisher and dispatching it on another publisher, the problem is that I cant…
Bruno
  • 1,032
  • 1
  • 16
  • 40
0
votes
0 answers

SwiftUI: unable to access @EnvironmentObject in view model

I'm building an app using SwiftUI / Combine and trying to do so in an MVVM pattern. I'm getting a little confused as to how best to expose certain properties and in particular, in relation to the Core Data implementation. In the main app file, I…
DevB1
  • 1,235
  • 3
  • 17
  • 43
0
votes
1 answer

Chaining n requests in Combine

I am trying to chain n requests with Combine. Let's assume I have 50 users and for each of them I need to do a single request to get a users data. I know that with flatMap you can pass one Publisher result into the next. But does that work with…
kchromik
  • 1,348
  • 2
  • 13
  • 42
0
votes
0 answers

Swift 5, Alamofire, Combine, MVVM throws error

func fetchData(from endpoint:ScrapeAPI )->AnyPublisher{ return AF.request(endpoint.mockurl, method: .post, parameters: endpoint.parameters, encoder:…