Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13808] View refreshing not triggered when ObservableObject is inherited in SwiftUI #56205

Closed
swift-ci opened this issue Nov 2, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 2, 2020

Previous ID SR-13808
Radar None
Original Reporter wesleybrito (JIRA User)
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 293b641023146de12657653eb8b6207b

Issue Description:

I don't know if it is a misunderstanding or if it is really a bug, but if i try to use some kind of baseViewModel that inherit an ObservableObject it doesn't trigger my ObservedObject and my UI is never updated.

class BaseViewModel: ObservableObject {
}


class ContentViewModel: BaseViewModel {
    @Published var value = ""
}

struct ContentView: View {
    @ObservedObject var viewModel = ContentViewModel()

    var body: some View {
        VStack {
            Text(viewModel.value)
            Button("change value") {
                self.viewModel.value = "\(Int.random(in: 1...10))"
            }
        }
    }
}

If i make some small changes in my ContentViewModel to inherit directly from the ObservableObject, every thing works as expected.

class ContentViewModel: ObservableObject {
    @Published var value = ""
}

The example project is on attachment.

@typesanitizer
Copy link

If I understand correctly, this is a SwiftUI-specific question, not necessarily related to the Swift toolchain itself. For questions related to frameworks in Apple's SDKs, I recommend posting your question on the Apple Developer forums or filing a feedback through feedbackassistant.apple.com .

This bug tracker is focused on Swift toolchain related bugs, such as those in the compiler, SwiftPM, SourceKit, the standard library and so on.

@typesanitizer
Copy link

(Marking as off-topic. Please re-open this bug if you feel that this has been closed incorrectly.)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 3, 2020

Comment by Wesley Brito (JIRA)

theindigamer (JIRA User) thanks for the redirect, i opened the bug to them.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants