Post

Replies

Boosts

Views

Activity

Swift compiler fails in Release (-O) when using generic ObservableObject with @Published on iOS < 26 in Xcode 26.3
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.
3
1
128
2d