Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppDelegate.swift:4:1 'UIApplicationMain' is deprecated; this is an error in Swift 6 #143044

Closed
jmagman opened this issue Feb 7, 2024 · 4 comments · Fixed by #146848
Closed
Assignees
Labels
P2 Important issues not at the top of the work list platform-ios iOS applications specifically platform-mac Building on or for macOS specifically t: xcode "xcodebuild" on iOS and general Xcode project management team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@jmagman
Copy link
Member

jmagman commented Feb 7, 2024

In Xcode 15.3 beta I see a deprecation warning in a newly created Flutter iOS Xcode project. @UIApplicationMain was renamed to @main in Swift 5.3.

AppDelegate.swift:4:1 'UIApplicationMain' is deprecated; this is an error in Swift 6

We already require Xcode 14, and Swift 5.3 was introduced in Xcode 12.

I bet the same is needed for @NSApplicationMain but I didn't check.

I'm not sure if there are other implications to using @main instead of @UIApplicationMain (scene delegates?)

@jmagman jmagman added platform-ios iOS applications specifically platform-mac Building on or for macOS specifically t: xcode "xcodebuild" on iOS and general Xcode project management team-ios Owned by iOS platform team fyi-tool For the attention of Flutter Tool team labels Feb 7, 2024
@hellohuanlin
Copy link
Contributor

From https://stackoverflow.com/questions/67429098/what-is-the-differnce-between-main-and-uiapplicationmain

Looks like for our use case they are the same (we don't have a custom main class to annotate)

@christopherfujino christopherfujino added the triaged-tool Triaged by Flutter Tool team label Feb 13, 2024
@christopherfujino
Copy link
Member

cc @eliasyishak

@flutter-triage-bot flutter-triage-bot bot removed fyi-tool For the attention of Flutter Tool team triaged-tool Triaged by Flutter Tool team labels Feb 13, 2024
@vashworth vashworth added P2 Important issues not at the top of the work list triaged-ios Triaged by iOS platform team labels Feb 14, 2024
@loic-sharma loic-sharma self-assigned this Apr 12, 2024
@loic-sharma
Copy link
Member

loic-sharma commented Apr 12, 2024

I'm not sure if there are other implications to using @main instead of @UIApplicationMain (scene delegates?)

@main requires Swift 5.3, which requires Xcode 12. That seems acceptable given our docs recommend installing Xcode 15.

Also from: https://forums.swift.org/t/se-0383-deprecate-uiapplicationmain-and-nsapplicationmain/62375/9

For example, one could go out of their way to declare a static func main() {} in their app delegate that, upon migration, would get automatically called instead of the main provided by an application delegate conformance:

@main // was @UIApplicationMain
actor AppDelegate: NSObject, NSApplicationDelegate {
  static func main() {
    fatalError("oops")
  }
}

They'd need to change the name of this function in addition to adopting the @main attribute to avoid the code exploding. This example would crash on launch, and a less contrived example wouldn't call UIApplicationMain or NSApplicationMain to set anything up, so I think the authors of such an implementation would catch it pretty quickly.

If we wanted to, we could guard against this by checking if the app delegate has something that looks like static func main(). However, this doesn't seem necessary; Swift's migration doesn't bother to check this either.

More details can be found in this proposal: https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md

auto-submit bot pushed a commit that referenced this issue Apr 16, 2024
This migrates Flutter to use the `@main` attribute introduced in Swift 5.3. The `@UIApplicationMain` attribute is deprecated and will be removed in Swift 6. See: https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md

This change is split into two commits:

1. ad18797 - This updates the iOS app template and adds a migration to replace `@UIApplicationMain` uses with `@main`. 
2. 8ecbb2f - I ran `flutter run` on each Flutter iOS app in this repository to verify the app migrates and launches successfully.

Part of #143044
auto-submit bot pushed a commit that referenced this issue Apr 18, 2024
This migrates Flutter to use the `@main` attribute introduced in Swift 5.3. The `@NSApplicationMain` attribute is deprecated and will be removed in Swift 6. See: https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md

This change is split into two commits:

1. a508d3e - This updates the macOS app template and adds a migration to replace `@NSApplicationMain` uses with `@main`. 
2. f434827 - I ran `flutter run -d macos` on each Flutter macOS app in this repository to verify the app migrates and launches successfully.

Follow-up to #146707
Fixes #143044
gilnobrega pushed a commit to gilnobrega/flutter that referenced this issue Apr 22, 2024
This migrates Flutter to use the `@main` attribute introduced in Swift 5.3. The `@UIApplicationMain` attribute is deprecated and will be removed in Swift 6. See: https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md

This change is split into two commits:

1. flutter@ad18797 - This updates the iOS app template and adds a migration to replace `@UIApplicationMain` uses with `@main`. 
2. flutter@8ecbb2f - I ran `flutter run` on each Flutter iOS app in this repository to verify the app migrates and launches successfully.

Part of flutter#143044
gilnobrega pushed a commit to gilnobrega/flutter that referenced this issue Apr 22, 2024
This migrates Flutter to use the `@main` attribute introduced in Swift 5.3. The `@NSApplicationMain` attribute is deprecated and will be removed in Swift 6. See: https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md

This change is split into two commits:

1. flutter@a508d3e - This updates the macOS app template and adds a migration to replace `@NSApplicationMain` uses with `@main`. 
2. flutter@f434827 - I ran `flutter run -d macos` on each Flutter macOS app in this repository to verify the app migrates and launches successfully.

Follow-up to flutter#146707
Fixes flutter#143044
Copy link

github-actions bot commented May 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 Important issues not at the top of the work list platform-ios iOS applications specifically platform-mac Building on or for macOS specifically t: xcode "xcodebuild" on iOS and general Xcode project management team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants