-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
The @Observable
macro only works on view models that are not within extensions. For example this works:
struct MyView: View {
...
}
extension MyView {
final class MyViewModel: ObservableObject {
...
}
}
but this does not:
extension MyView {
@Observable final class MyViewModel {
...
}
}
Steps to reproduce
- Create a simple view with a basic view model using the
@Observable
macro. - Wrap the view model in an extension of the view; this should cause the error.
Expected behavior
Successful compilation.
Environment
- Swift compiler version info: swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0 - Xcode 15.0 Beta
- Deployment target: iOS 17.0 Beta
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels