0

I'm trying to make a SwiftUI created on Xcode 13 work on Xcode 11 (or iOS 13).

There's a similar post here but the suggestions doesn't seem to work on Xcode 11.

My current entrypoint looks like:

@main  // <- this does not work on Xcode 11!
struct MyAppWrapper {
    static func main() {
        if #available(iOS 14.0, *) {
            MyApp.main()
        } else {
            UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self))
        }
    }
}

@available(iOS 14.0, *)
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

As in the comment above, Xcode 11 doesn't support @main. I would like to use AppDelegate for iOS 13, but use Scene and WindowsGroup method on iOS 14 and above.

I can't believe making a SwiftUI project that works across iOS 13~15 is this difficult..

What else can I try?


Update

Info.plist:

enter image description here

MyApp.swift:

enter image description here

AppDelegate.swift:

enter image description here

SceneDelegate.swift:

enter image description here

shinhong
  • 406
  • 4
  • 13
  • There's no need to use Xcode 11 - just set your app's deployment target to iOS 13 and you're done. – Gereon Mar 22 '22 at 10:48
  • @Gereon Thanks for the comment. I'm using Xcode 11 so that I can `build` and `test` my project on iOS 13 SDK. Are you suggesting that even with the newer versions of Xcode, I can still `build` and `test` using iOS 13 SDK? (FYI, I'm using Github Actions for CI/CD) – shinhong Mar 22 '22 at 10:52
  • No, with Xcode 13 you're building with the iOS 15 SDK, but since need to support iOS 14 and 15, that's precisely what you need and want to do. Setting the deployment target is really all you need to do, the compiler will keep you from using newer features without appropriate `if #available` checks. – Gereon Mar 22 '22 at 11:32
  • @Gereon Not only iOS 14 and 15, I also need to support iOS 13, which is whole point of this question. – shinhong Mar 22 '22 at 11:51
  • Does this answer your question? [How to generate iOS 13 SwiftUI project in XCode?](https://stackoverflow.com/questions/69703928/how-to-generate-ios-13-swiftui-project-in-xcode) – lorem ipsum Mar 22 '22 at 11:52
  • The trick is knowing the difference. iOS 13 required an `AppDelegate` as an entry point. Xcode 11 is irrelevant and unnecessary. You just have to make the `AppDelegate` the entry point with `@UIApplicationMain`. See the link above. – lorem ipsum Mar 22 '22 at 11:54
  • @loremipsum Neither of the answers to the SO post helped, unfortunately. I followed the first answer but all I see is black screen when I launch the app. The second answer is exactly the same as my configurations. – shinhong Mar 22 '22 at 12:07
  • @loremipsum Well, yes I did, and I'm pretty sure that I'm not missing any of the steps in the answer :( – shinhong Mar 22 '22 at 12:11
  • (Correct me if I'm wrong) I think I need Xcode 11 in that it comes with iOS 13 SDK. That's the only way to `build` and `test` a project in iOS 13, **especially during CI/CD context**. – shinhong Mar 22 '22 at 12:13
  • I just tried it myself and they have made a couple of minor changes. The 2 blank entries in the `Info.plist` have to be removed – lorem ipsum Mar 22 '22 at 12:26
  • That isn't correct. I just made an iOS 13 project with the info in that link (not the one setup like yours) and I have all of the iOS 13 simulators. and a project with the deployment target of iOS 13. – lorem ipsum Mar 22 '22 at 12:29
  • @loremipsum What do you mean by *the 2 blank entries*? I don't see any blank entries in `Info.plist`, both in mine and in the answers'. – shinhong Mar 22 '22 at 12:41
  • I took them out already in the photo, in the area that has "Configuration Name" in the `Info.plist` there were 4 entries instead of 2. Just make you manifest look just like the photo that is there now. – lorem ipsum Mar 22 '22 at 12:46
  • @loremipsum oh, I just noticed that you were the author of the answer.. I added some screenshots of the files. Can you take a look? – shinhong Mar 22 '22 at 12:58
  • `MyApp.swift` goes away. Remove that from the target. The `SceneDelegate` calls the `ContentView` you don't need that code. – lorem ipsum Mar 22 '22 at 13:29
  • @loremipsum Turned out it was xcode bug. I switched to another simulator with the same iOS version and it worked. Thanks for sticking with me! – shinhong Mar 22 '22 at 14:20
  • @shinhong I'm glad you sorted it out. – lorem ipsum Mar 22 '22 at 15:07

0 Answers0