On Xcode 27, the compiler incorrectly errors when a @State variable definition is placed on multiple lines. The code compiles without any issues on Xcode 26 and is valid Swift. The issue is fixed if the var definition is placed on a single line.
The following code produces issues:
@State
internal
var bodyText = "Hi"
However, the code below works:
@State internal var bodyText = "Hi"
The issue is reproducible in any new project with a simple view:
import SwiftUI
import Playgrounds
@main struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State
internal
var bodyText = "Hi"
var body: some View {
Text(bodyText)
.padding()
}
}
#Preview {
ContentView()
}
The expected behavior is for valid Swift code to not trigger compiler error.
Filed FB23044343
Thank you for filing this report.
This looks to be brought with the changes of @State becoming a Swift macro rather than a property wrapper.
I can see some activity in that feedback report you shared, I'll make sure it is seen by the relevant engineering team directly.
Keep an eye on the report. There, updates will be provided to you - if they have questions or updates if your report has been resolved in any way.
Please use the inline workaround you provided. I encourage you to test new versions as they are released and update us here and in the Feedback Report so the engineers have a good sense of timeline for this issue.
For more information, see TN3211: Resolving SwiftUI source incompatibilities for State and ContentBuilder
Travis