I have a SwiftUI app that is targeting iOS 13 and higher. I would like to conditionally use the @StateObject property wrapper if I am running on iOS 14, as it would fix so many bugs I've had to workaround on iOS 13.
Is there any way to conditionally do this via #ifdef or #if available(iOS 14, *) calls or similar? I'm happy to have a completely separate implementation of a given view for iOS 14.
I've tried this but it of course doesn't compile.
struct MyView: View {
if #available(iOS 14, *) {
@StateObject var viewModel: ViewModel()
} else {
@ObservedObject var viewModel: ViewModel
}