Opt out of UISceneDelegate/SwiftUI on iOS
This is something I faced also, and there's a few scenarios at play here:
- If you want to work on an existing
UIKit
app in Xcode 11, simply open it up and it should work fine. All my apps have, with noSceneDelegate
file nor any changes toAppDelegate
or storyboards. - If you want to create a new
UIKIT
app targeting iOS 13, simply create it while making sure you leave the "Use SwiftUI" checkbox unchecked.
But I'm wondering if you are facing the third scenario - one that I did about a week ago. Creating a new `UIKit app targeting something earlier than iOS 13. (I actually targeted iOS 9!)
Yep, your template will give you 15 errors (as of beta 5), along with a SceneDelegate
file/class. Fortunately, Xcode will help you auto-correct all but one.
The last one is to add one line that is part of the SceneDelegate
class but unfortunately Apple left it out of the AppDelegate
class - which after more than a dozen @available(iOS 13.0, *)
clauses means you've opted out of SceneDelegate
if running iOS 12 and guess what? It's not there in ApDelegate
!
Add this to your AppDelegate:
var window: UIWindow?
At that point, your should have a running UIKit
app targeted for iOS 12 and earlier.
While you should embrace using scenes when your app is run under iOS 13 and later, you can fully opt out while you still support iOS 12 or earlier.
Completely remove the “Application Scene Manifest” entry from Info.plist.
If there is a scene delegate class, remove it.
If there are any scene related methods in your app delegate, remove those methods.
If missing, add the property
var window: UIWindow?
to your app delegate.
Your app should now only use the app delegate and under iOS 13 it should have the same life cycle as iOS 12.
Note: None of this is specific to Swift or SwiftUI.