I have read the migration guide and am still stuck on this one. In the spirit of the migration guide ...
OLD
class MyClass: ObservableObject {
@Published var myVariable: String = "Need to know"
var subscriptions: Set<AnyCancellable> = []
init() {
$myVariable.sink { updated_variable in
//Need to operate
}.store(in: &subscriptions)
}
}
NEW
@Observable class MyClass {
var myVariable: String = "Need to know"
var subscriptions: Set<AnyCancellable> = []
init() {
/*
Error!
Cannot find '$myVariable' in scope
*/
$myVariable.sink { updated_variable in
//Need to operate
}.store(in: &subscriptions)
}
}
I really liked subscribing to and for that matter assigning to @Published variables with combine. Can I still do this in any way?
No, I don't think this is possible anymore because the @Observable
macro isn't using Combine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With