Post not yet marked as solved
Post marked as unsolved with 1 replies, 1,155 views
This code crashes ("Unexpectedly found nil while unwrapping an Optional value")
import Combine
class Receiver {
		var value: Int!
		var cancellables = Set<AnyCancellable>([])
		init(_ p: AnyPublisher<Int,Never>) {
				p.assign(to: \.value, on: self).store(in: &cancellables)
		}
}
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?