Customize handling of asynchronous events by combining event-processing operators using Combine.

Combine Documentation

Posts under Combine tag

23 Posts
Sort by:
Post not yet marked as solved
1 Replies
1.7k Views
Hello For apps built with xcode 13 but ran on ios 16 beta devices, im seeing a potential leak in Combine that i suspect may be causing a breaking bug(the view fails to load anything on subsequent visits after being dismissed, which im suspecting is due to the leaked observable object) . The issue is resolved when built with Xcode 14 Beta, no bug and no leak I am triggering a flow multiple times and seeing the instances of an @ObservableObject used as a @StateObject in a view keep going up in the memory debugger, without the corresponding view leaking to accompany it like ive seen before. so the observable object is being leaked I see the following in the memory graph debugger. It indicates a BoxVTable relation to the observable datastore, which i presume is an internal type i dont have access to, when the view has disappeared Any Ideas? ive checked all the typical closure leak possibilities ive fixed before and this seems to be different
Posted
by
Post not yet marked as solved
3 Replies
4k Views
I am working on a library, a Swift package. We have quite a few properties on various classes that can change and we think the @Published property wrapper is a good way to annotate these properties as it offers a built-in way to work with SwiftUI and also Combine. Many of our properties can change on background threads and we've noticed that we get a purple runtime issue when setting the value from a background thread. This is a bit problematic for us because the state did change on a background thread and we need to update it at that time. If we dispatch it to the main queue and update it on the next iteration, then our property state doesn't match what the user expects. Say they "load" or "start" something asynchronously, and that finishes, the status should report "loaded" or "started", but that's not the case if we dispatch it to the main queue because that property doesn't update until the next iteration of the run loop. There also isn't any information in the documentation for @Published that suggests that you must update it on the main thread. I understand why SwiftUI wants it on the main thread, but this property wrapper is in the Combine framework. Also it seems like SwiftUI internally could ask to receive the published updates on the main queue and @Published shouldn't enforce a specific thread. One thing we are thinking about doing is writing our own property wrapper, but that doesn't seem to be ideal for SwiftUI integration and it's one more property wrapper that users of our package would need to be educated about. Any thoughts on direction? Is there anyway to break @Published from the main thread?
Posted
by
Post not yet marked as solved
1 Replies
1.2k Views
This code crashes ("Unexpectedly found nil while unwrapping an Optional value") import Combine class Receiver { &#9;&#9;var value: Int! &#9;&#9;var cancellables = Set<AnyCancellable>([]) &#9;&#9;init(_ p: AnyPublisher<Int,Never>) { &#9;&#9;&#9;&#9;p.assign(to: \.value, on: self).store(in: &cancellables) &#9;&#9;} } let receiver = Receiver(Just(5).eraseToAnyPublisher()) It does not crash if I use p.sink { self.value = $0 }.store(in: &cancellables) instead of the assign, and it does not crash if I do not use an optional for the value-property. To me this looks like a bug in Swift's constructor code, but maybe I am overlooking something?
Posted
by