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

[macOS] Adopt @Observable in SwiftUI code #4511

Conversation

harlanhaskins
Copy link

@harlanhaskins harlanhaskins commented Jan 3, 2025

This moves off of ObservableObject and @Published over to @Observable, which is preferred as it allows views to observe changes on a per-property basis rather than an entire object at a time.

I went through the app and tried to compare behavior where I could, and I couldn't spot any visual differences, but I am sure there's good chance I have missed something.

This also requires updating the minimum macOS deployment target to 14.0. If that is unacceptable, I am happy just closing this PR. Increasing the deployment target required updating some onChange callsites to avoid depreciation warnings.

This moves off of ObservableObject and @published over to @observable, which is preferred as it allows views
to observe changes on a per-property basis rather than an entire object at a time.

I went through the app and tried to compare behavior where I could, and I couldn't spot any visual differences,
but I am sure there's good chance I have missed something.

This also requires updating the minimum macOS deployment target to 14.0. If that is unacceptable, I am happy just
closing this PR.
self.delegate?.cellSizeDidChange(to: size)
}
.onChange(of: viewModel.surfaceTree?.hashValue) { _ in
.onChange(of: viewModel.surfaceTree?.hashValue) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that Container is now @Observable, this may no longer be required. A view will observe the properties of all @Observable instances it reads from during body, which means we no longer need to manually propagate changes up from child objects. I am not confident enough to remove this, however.

@mitchellh
Copy link
Contributor

macOS 14 as a minimum deployment target is unacceptable. We want to continue supporting all supported Apple platforms. That’s the reason I was holding back. Sorry! But thanks for trying…

@harlanhaskins
Copy link
Author

No worries, this was still a fun way to get acquainted with the codebase. Thanks for the quick reply!

@harlanhaskins harlanhaskins deleted the harlanhaskins/swiftui-observable branch January 3, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants