combine

Swift Combine properties inheritance throws 'Fatal error: Call of deleted method' on Xcode 11.4 beta 2 / iOS 13.4

主宰稳场 提交于 2020-05-11 06:42:36
问题 I'm trying to using Swift Combine to get the changed event of a property. I have this class that publish the isLogged property class CurrentUser: Account { static let me = CurrentUser() //Singleton @Published var isLogged: Bool = false } that inherit from this other class that publish the profileImageVersion property class Account { @Published var profileImageVersion: String? init(){ self.profileImageVersion = "" } } I'm trying to subscribe to the published inherit profileImageVersion

Best data-binding practice in Combine + SwiftUI?

那年仲夏 提交于 2020-05-10 07:32:07
问题 In RxSwift it's pretty easy to bind a Driver or an Observable in a View Model to some observer in a ViewController (i.e. a UILabel ). I usually prefer to build a pipeline, with observables created from other observables , instead of "imperatively" pushing values, say via a PublishSubject ). Let's use this example: update a UILabel after fetching some data from the network RxSwift + RxCocoa example final class RxViewModel { private var dataObservable: Observable<Data> let stringDriver: Driver

Best data-binding practice in Combine + SwiftUI?

限于喜欢 提交于 2020-05-10 07:29:10
问题 In RxSwift it's pretty easy to bind a Driver or an Observable in a View Model to some observer in a ViewController (i.e. a UILabel ). I usually prefer to build a pipeline, with observables created from other observables , instead of "imperatively" pushing values, say via a PublishSubject ). Let's use this example: update a UILabel after fetching some data from the network RxSwift + RxCocoa example final class RxViewModel { private var dataObservable: Observable<Data> let stringDriver: Driver

Merge all lines that are identical aside from a key field and make key field a range [closed]

那年仲夏 提交于 2020-05-09 17:24:04
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last month . I've been looking at a lot of posts and haven't quite found what I'm looking for. I'm not sure how to go about taking the following sample data: host1 input nic1 ip1 ip2 PROT 30000 10 host1 input nic1 ip1 ip2 PROT 40000 10 host1 input nic1 ip1 ip2 PROT 50000 10 host1 input nic1 ip1

SwiftUI: ForEach using Array/Index crashes when rows are deleted

我与影子孤独终老i 提交于 2020-05-09 05:59:49
问题 I've seen several posts about this, but so far none of the solutions seem to be working for me. I'm trying to create an array of Identifiable items using ForEach -- with both a Text() and Toggle() view inside. The array is stored in a @Published property of an @ObservableObject . I'm currently looping through the indices to create the toggle bindings (as suggested in other posts). Everything appears to be working, until I try to delete a row. (Specifically the last row - which triggers a

Where is the header that defines the `publisher(for:)` method that yields a KeyValueObservingPublisher?

╄→гoц情女王★ 提交于 2020-04-17 22:52:21
问题 I can see the Foundation header that defines NSObject.KeyValueObservingPublisher . But I can't find the header that defines the publish(for:) method that returns this publisher. And I can’t find it in the documentation. It must involve NSObject, because only an NSObject can be observed with KVO. And it must come in the forms publisher(for:) and publisher(for:options:) , because that's what code completion offers me in Xcode. But where is code completion getting that information from? 回答1: It

How to update UIViewRepresentable with ObservableObject

五迷三道 提交于 2020-04-12 19:47:48
问题 I'm trying to learn Combine with SwiftUI and I'm struggling how to update my view (from UIKit) with ObservableObject (previously BindableObject ). The issue is that, obviously, method updateUIView will not fire once the @Published object sends the notification it was changed. class DataSource: ObservableObject { @Published var locationCoordinates = [CLLocationCoordinate2D]() var value: Int = 0 init() { Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in self.value += 1 self

List reload animation glitches

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-05 05:08:59
问题 So I have a list that changes when user fill in search keyword, and when there is no result, all the cells collapse and somehow they would fly over to the first section which looks ugly. Is there an error in my code or is this an expected SwiftUI behavior? Thanks. import SwiftUI struct ContentView: View { @ObservedObject var viewModel = ViewModel(photoLibraryService: PhotoLibraryService.shared) var body: some View { NavigationView { List { Section { TextField("Enter Album Name", text:

List reload animation glitches

元气小坏坏 提交于 2020-04-05 05:08:45
问题 So I have a list that changes when user fill in search keyword, and when there is no result, all the cells collapse and somehow they would fly over to the first section which looks ugly. Is there an error in my code or is this an expected SwiftUI behavior? Thanks. import SwiftUI struct ContentView: View { @ObservedObject var viewModel = ViewModel(photoLibraryService: PhotoLibraryService.shared) var body: some View { NavigationView { List { Section { TextField("Enter Album Name", text:

Why does Combine's receive(on:) operator swallow errors?

家住魔仙堡 提交于 2020-03-25 22:39:35
问题 The following pipeline: enum MyError: Error { case oops } let cancel = Fail<Int, Error>(error: MyError.oops) .print("1>") .print("2>") .sink(receiveCompletion: { status in print("status>", status) }) { value in print("value>", value) } Outputs: 1>: receive subscription: (Empty) 2>: receive subscription: (Print) 2>: request unlimited 1>: request unlimited 1>: receive error: (oops) 2>: receive error: (oops) status> failure(__lldb_expr_126.MyError.oops) The problem However, if I insert a receive