forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Migrate @UIApplicationMain attribute to @main (#146707)
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/flutter@ad18797 - This updates the iOS app template and adds a migration to replace `@UIApplicationMain` uses with `@main`. 2. flutter/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/flutter#143044
- Loading branch information
1 parent
5a0369d
commit 194fefa
Showing
14 changed files
with
173 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/flutter_tools/lib/src/ios/migrations/uiapplicationmain_deprecation_migration.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import '../../base/file_system.dart'; | ||
import '../../base/project_migrator.dart'; | ||
import '../../xcode_project.dart'; | ||
|
||
const String _appDelegateFileBefore = r''' | ||
@UIApplicationMain | ||
@objc class AppDelegate'''; | ||
|
||
const String _appDelegateFileAfter = r''' | ||
@main | ||
@objc class AppDelegate'''; | ||
|
||
/// Replace the deprecated `@UIApplicationMain` attribute with `@main`. | ||
/// | ||
/// See: | ||
/// https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md | ||
class UIApplicationMainDeprecationMigration extends ProjectMigrator { | ||
UIApplicationMainDeprecationMigration( | ||
IosProject project, | ||
super.logger, | ||
) : _appDelegateSwift = project.appDelegateSwift; | ||
|
||
final File _appDelegateSwift; | ||
|
||
@override | ||
Future<void> migrate() async { | ||
// Skip this migration if the project uses Objective-C. | ||
if (!_appDelegateSwift.existsSync()) { | ||
logger.printTrace( | ||
'ios/Runner/AppDelegate.swift not found, skipping @main migration.', | ||
); | ||
return; | ||
} | ||
|
||
// Migrate the ios/Runner/AppDelegate.swift file. | ||
final String original = _appDelegateSwift.readAsStringSync(); | ||
final String migrated = original.replaceFirst(_appDelegateFileBefore, _appDelegateFileAfter); | ||
if (original == migrated) { | ||
return; | ||
} | ||
|
||
logger.printWarning( | ||
'ios/Runner/AppDelegate.swift uses the deprecated @UIApplicationMain attribute, updating.', | ||
); | ||
_appDelegateSwift.writeAsStringSync(migrated); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/flutter_tools/templates/app_shared/ios-swift.tmpl/Runner/AppDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters