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/Combine: FetchedResults Error Accessing StateObject's object without being installed on a View

I'm trying to create an CoreData Entity observer: @FetchRequest(sortDescriptors: []) var todoResult: FetchedResults init() { todoResult.publisher.sink { _ in print("sink") } receiveValue: { todos in …
user2924482
  • 8,380
  • 23
  • 89
  • 173
0
votes
1 answer

How to merge multiple network calls’ responses into an array? With or without Combine?

Working with flagpedia.net/download/api It has two endpoints: 1 - Returns [String:String] dictionary of code-country pairs, like [“us”:”United States”] as a json 2 - Returns an image data for a country code and specified image size, example url…
iilyasov
  • 23
  • 1
  • 7
0
votes
1 answer

decoding empty array not throwing specified array

I have RestManager class for fetching data from Internet. I wanted to made special case when empty array is decoded function returns error. So I made this class RestManager { func fetchData(url: URL) -> AnyPublisher
0
votes
2 answers

SwiftUI: Property type does not match wrappedValue for type FetchedResults

I'm trying to implement this solution: Combine, Publishers, and Core Data but I'm getting the following error: Here is my implantation: class DataModel: ObservableObject { @Published var customers: [Task] = [] private var cancellables =…
user2924482
  • 8,380
  • 23
  • 89
  • 173
0
votes
1 answer

Swift Combine: sink() called after core data entity deletion

I am using this code in a SwiftUI view model: car.publisher(for: \.sold, options: [.new]) .removeDuplicates() .receive(on: RunLoop.main) .sink { [weak self] sold in guard let self = self else { return } …
zumzum
  • 17,984
  • 26
  • 111
  • 172
0
votes
2 answers

SwiftUI: toggle buttons state inside List

I try to implement a simple player app with a tracks list where each row has a play button, and if I press Play for one track, current playing track (if any) should stop playing (in this case Play button should change icon). Here I got some…
schmidt9
  • 4,436
  • 1
  • 26
  • 32
0
votes
1 answer

Swift combine: assign value in .sink, but can't use .assign

$overallSecondsLeft .map { ti -> String? in let seconds = (ti.rounded(.up)) if seconds > 0 { return { String(format: "%02d:%02d", $0.0, $0.1) }(seconds.minutesAndSecondsOverHours) } …
Alexey
  • 79
  • 7
0
votes
1 answer

Swift: Return publisher after another publisher is done

I'm very new to the concept Publishers and I'm creating a networking service using dataTaskPublisher on URLSession. There is a case for refreshing token and I have a refreshToken() method which returns AnyPublisher: func…
Maysam
  • 7,246
  • 13
  • 68
  • 106
0
votes
0 answers

Call to get publishers never returns in combine swift

I have a combine construct to combine calls to the functions that return AnyPublishers. [credVendor.credentials() and credVendor.accessToken()]. The issue here is that the call to the publisher does not return back sometimes and the application…
Sabya
  • 197
  • 4
  • 17
0
votes
2 answers

Combine - how to proceed to decode a local json file if online fetch failed?

I have an up-to-date json file hosted online and a local json file in my Xcode workspace. I would like to proceeed to decode a locally stored file if fetching failed: MyError.fetchError e.g. for no internet connection. This is the pipeline: func…
thbswf
  • 3
  • 1
0
votes
1 answer

Reactive Swift Signal Producer conversion code to Combine.Publisher doesn't work with combine latest

Here's my code to convert ReactiveSwift Signal Producers to Combine.Publishers import ReactiveSwift import Combine /// convert SignalProducer -> Publisher public struct ReactiveSwiftPublisher: Publisher { public…
Yogurt
  • 2,913
  • 2
  • 32
  • 63
0
votes
2 answers

How to use Combine to show elastic search results using network while falling back on cache in Swift

I have a function which returns a list of Items using elastic search and falls back on realm cache. I'm wondering how can I use Combine to achieve the same. I am trying to do something like this where I have a publisher for each store but I am…
Rush B
  • 29
  • 1
  • 9
0
votes
1 answer

How two handle errors in async calls in swift combine?

I have two async calls to fetch data from the server, but I want them to handle them as a single response, also want to handle errors for each response. for example, here I have two methods m1(), m2() each can throw the different types of errors. We…
Jessy
  • 157
  • 1
  • 10
0
votes
1 answer

Using flatMap in RestManager with generic function not working

I am new to Combine, so I wanted to create class RestManager for networking with generic fetchData function. Function is returning AnyPublisher, Never> where ErrorType is enum with .noInternetConnection, .empty and .general…
0
votes
1 answer

Swift: execute an operation conditionally on Publisher

I'm using Combine for networking and I want to have some of the combine operations executed only if a certain condition is present, for instance if a local boolean variable needsDecoding is true I want to add .decode(type:,decoder:): if…
Maysam
  • 7,246
  • 13
  • 68
  • 106