When building a SwiftUI project in Xcode 26.3, Swift compilation fails in the Release configuration with Optimization Level set to -O, when the iOS deployment target is lower than iOS 26 (e.g. iOS 16, 17, or 18).
The failure occurs when using a generic class conforming to ObservableObject that contains a @Published property.
The same code:
- Compiles successfully in Xcode 16.3 (Release, -O) with iOS 16/17/18
- Compiles successfully in Xcode 26.x when the deployment target is set to iOS 26
- Compiles successfully in Xcode 26.x Debug configuration (-Onone)
- Compiles successfully in Xcode 26.x Release when optimization is disabled (-Onone)
However, in Xcode 26.3, the build consistently fails in Release (-O) when targeting iOS 16, 17, or 18.
This appears to be a Swift compiler optimization issue related to generics, ObservableObject, @Published, and back-deployment to iOS versions prior to iOS 26.
STEPS TO REPRODUCE
- Create a new SwiftUI App project using Xcode 26.3.
- Leave all project settings at default (Swift version 5).
- Set the iOS Deployment Target to iOS 16, 17, or 18.
- Use the following minimal code:
import SwiftUI
internal import Combine
@MainActor
class CommonViewModel<Item>: ObservableObject {
@Published var listArray = [Item]()
}
class ContentViewModel: CommonViewModel<String> {
func reloadData() {
self.listArray = ["1"]
}
}
struct ContentView: View {
@StateObject private var viewModel = ContentViewModel()
var body: some View {
Color.clear
.onAppear {
viewModel.reloadData()
}
}
}
- Build and run the app using the Release configuration.
Right. That’s the Swift compiler crashing, which is something it should never do. I recommend that you file a bug about it. And as this is specific to Apple technologies, you’ll have to use Feedback Assistant rather than the Swift open source bug process.
Please post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"