Xcode 12 は 「Life Cycle: SwiftUI App」と言う設定ができるようになりました。
![Life Cycle 「SwiftUI App」](https://mjeld.com/wp-content/uploads/2021/08/2021-08-221737.gif)
protocol App継承で下記のようなシンプルな構成になりました。そして、AppDelegate.swiftがなくなりました。
@main struct プロジェクト名: App { var body: some Scene { WindowGroup { ContentView() } } }
AppDelegateが必要な場合は、下記のようなAppDelegateクラスを用意します。
import Foundation import Cocoa class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { } func applicationWillTerminate(_ aNotification: Notification) { } }
struct プロジェクト名:App{}側に@NSApplicationDelegateAdaptor()を追記してやります。
@main struct プロジェクト名: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } }