combine

How to set multiple EnvironmentObjects which are same type

被刻印的时光 ゝ 提交于 2020-07-30 05:38:40
问题 I found this question SwiftUI: Putting multiple BindableObjects into Envionment the answer said environmentObject(ObservableObject) returns modified view, therefore I can make call chain for multiple environmentObject. like let rootView = ContentView() .environmentObject(firstBindable) .environmentObject(secondBindable) and I wonder what is result if firstBindable and secondBindable are same type. how .environmentObject() knows what is exect value which is a programmer intended to set between

How to set multiple EnvironmentObjects which are same type

谁说我不能喝 提交于 2020-07-30 05:38:30
问题 I found this question SwiftUI: Putting multiple BindableObjects into Envionment the answer said environmentObject(ObservableObject) returns modified view, therefore I can make call chain for multiple environmentObject. like let rootView = ContentView() .environmentObject(firstBindable) .environmentObject(secondBindable) and I wonder what is result if firstBindable and secondBindable are same type. how .environmentObject() knows what is exect value which is a programmer intended to set between

How to: Using Combine to react to CoreData changes in the background

余生颓废 提交于 2020-07-19 05:06:43
问题 I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a notes app, I want to asynchronously calculate the total number of words in all notes. The problem currently lies with the fact that NSManagedObject context is explicitly bound to thread and you are discouraged from using NSManagedObject s outside

How to: Using Combine to react to CoreData changes in the background

我的梦境 提交于 2020-07-19 05:03:49
问题 I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a notes app, I want to asynchronously calculate the total number of words in all notes. The problem currently lies with the fact that NSManagedObject context is explicitly bound to thread and you are discouraged from using NSManagedObject s outside

How to: Using Combine to react to CoreData changes in the background

一世执手 提交于 2020-07-19 05:03:43
问题 I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a notes app, I want to asynchronously calculate the total number of words in all notes. The problem currently lies with the fact that NSManagedObject context is explicitly bound to thread and you are discouraged from using NSManagedObject s outside

Implementing reconnection with URLSession publisher and Combine

﹥>﹥吖頭↗ 提交于 2020-07-19 04:04:26
问题 I'm wondering if there is a way to implement reconnection mechanism with new Apple framework Combine and use of URLSession publisher tried to find some examples in WWDC 2019 tried to play with waitsForConnectivity with no luck (it even not calling delegate on custom session) tried URLSession.background but it crashed during publishing. I'm also not understanding how do we track progress in this way Does anyone already tried to do smth like this? upd: It seems like waitsForConnectivity is not

Implementing reconnection with URLSession publisher and Combine

只谈情不闲聊 提交于 2020-07-19 04:04:10
问题 I'm wondering if there is a way to implement reconnection mechanism with new Apple framework Combine and use of URLSession publisher tried to find some examples in WWDC 2019 tried to play with waitsForConnectivity with no luck (it even not calling delegate on custom session) tried URLSession.background but it crashed during publishing. I'm also not understanding how do we track progress in this way Does anyone already tried to do smth like this? upd: It seems like waitsForConnectivity is not

How to mock DataTaskPublisher?

好久不见. 提交于 2020-07-16 05:39:09
问题 I'm trying to write some unit tests for my API using URLSession.DataTaskPublisher. I've found an already existing question on Stackoverflow for the same but I'm struggling to implement a working class using the proposed solution. Here's the existing question: How to mock URLSession.DataTaskPublisher protocol APIDataTaskPublisher { func dataTaskPublisher(for request: URLRequest) -> URLSession.DataTaskPublisher } class APISessionDataTaskPublisher: APIDataTaskPublisher { func dataTaskPublisher

How do I check the current progress of URLSession.dataTaskPublisher?

孤人 提交于 2020-07-08 11:48:24
问题 I'm using a dataTaskPublisher to fetch some data: func downloadData(_ req: URLRequest) { self.cancelToken = dataTaskPublisher(for: req).sink { /* ... */ } } If the function is called while the request is in progress, I would like to return. Currently I either: 1. Set the cancelToken to nil in the sink or 2. Crate and manage a isDownloading variable. Is there a built-in way to check if the dataTaskPublisher is running (and optionally its progress)? 回答1: I mostly agree with @Rob, however you

Performing side effects on Publisher

為{幸葍}努か 提交于 2020-07-04 03:27:04
问题 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 wrapper for a delegate provided by a 3rd party SDK. It's and SDK for interacting with BLE devices. I have methods like startScanning and stopScanning and what I want to achieve is to react to signals and call stopScanning as a side effect of any