Backward compatibility with iOS13

If target is set to iOS13 - following error appears

'main()' is only available in iOS 14.0 or newer

Code Block swift
@available(iOS 14.0, *)
@main
struct MainApp: App {
    var body: some Scene {
        WindowGroup {
            Text("Hello, world!").padding()
        }
    }
}

What are the options and best practises to start using new SwiftUI concepts, views and features while maintaining backward compatibility with iOS13 ?

Answered by lepuso in 615423022
Thank you for the reply!

To summarize my understanding - to have backward compatibility with iOS13 "UIKit App Delegate" and "UIKit Scene Delegate" still has to be used (so code refactoring to @main will require to drop support for iOS13). While some new cool features like if let ... inside the view builders started to work out of the box even for target iOS13.

It looks as if you created this directly from a template in Xcode 12 beta. If you want to target iOS 13, create a new project again and make sure you choose "UIKit App Delegate" for the "Life Cycle" option in the template configuration. That will use the old model that is supported in iOS 13 and still supported in iOS 14. Keep "Swift UI" chosen for the "Interface" option and you'll still end up with a fresh project that is wired up for Swift UI.
Accepted Answer
Thank you for the reply!

To summarize my understanding - to have backward compatibility with iOS13 "UIKit App Delegate" and "UIKit Scene Delegate" still has to be used (so code refactoring to @main will require to drop support for iOS13). While some new cool features like if let ... inside the view builders started to work out of the box even for target iOS13.

I'm having this problem but when trying to add an iOS 14 widget to my iOS 13 Objective-C app in Xcode 12 beta 6.

I've added the new widget as a .swift file, but when I try to build it, it fails because: 'main()' is only available in iOS 14.0 or newer

The target for the app is iOS 13, and the target for the widget is iOS 14. The iOS 13 widget still works perfectly fine.

If I remove @main from the widget swift file I can see the preview correctly in the SwiftUI in Xcode, but when I add it back, it fails to build.

How do I create a new widget for an Objective-C app?! (This app has too much code in it to convert to Swift.)
Backward compatibility with iOS13
 
 
Q