Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine and Observable Macro iOS 17

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?

like image 823
Jon Vogel Avatar asked Oct 19 '25 19:10

Jon Vogel


1 Answers

No, I don't think this is possible anymore because the @Observable macro isn't using Combine

like image 99
Mikaela Caron Avatar answered Oct 22 '25 12:10

Mikaela Caron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!