I would love my SwiftUI views to support the new modifiers in iOS 14 (e.g. .navigationTitle), but still run on iOS 13 (e.g. using deprecated .navigationBarTitle). What is the best way to add conditional #if available code for view modifiers?
The only way I can find to do it is by extracting every subview, and putting #if available blocks around every view declaration — this seems very tedious, as I am redefining each view twice.
E.g.
Is there a better way to just add conditional code only around the modifiers? Thanks in advance.
The only way I can find to do it is by extracting every subview, and putting #if available blocks around every view declaration — this seems very tedious, as I am redefining each view twice.
E.g.
Code Block Swift struct SettingsView: View { var body: some View { NavigationView { if #available(iOS 14.0, *) { SettingsContentView() .navigationTitle("Settings") } else { SettingsContentView() .navigationBarTitle("Settings") } } } }
Is there a better way to just add conditional code only around the modifiers? Thanks in advance.