Skip to content

@ObservedObject Equivalent #22

Closed Answered by david-swift
s-k asked this question in Q&A
Apr 18, 2024 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

I added support for the observation framework on the 1.0.0 branch for the next major version as the implementation required some breaking changes. I decided to make State handle both value types and observable reference types:

import Adwaita
import Observation

@Observable
class CounterModel {

    var count = 0 {
        didSet {
            print("Hi")
        }
    }

}

struct CounterDemo: View {

    @State private var count = CounterModel()

    var view: Body {
        VStack {
            HStack {
                CountButton(icon: .goPrevious) { count.count -= 1 }
                Text("\(count.count)")
                    .style("title-1")
                    .frame(minWidth: 100)

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@david-swift
Comment options

@david-swift
Comment options

@s-k
Comment options

@david-swift
Comment options

@s-k
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by s-k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants