Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftUI App/Scene - SwiftUI App/Scene の実際

notoroid
September 30, 2020

SwiftUI App/Scene - SwiftUI App/Scene の実際

札幌iPhoneアプリ開発懇談会2020年9月勉強会資料。

内容: Xcode12で新規プロジェクトのオプションにLife Cycleが追加され新たに選べる選択肢にSwiftUI App Life Cycleを選択可能となりました。新たな選択肢は簡潔なコードが売りですがその実際について説明します。

#iOS #SwiftUI #Swift #WWDC2020

notoroid

September 30, 2020
Tweet

More Decks by notoroid

Other Decks in Programming

Transcript

  1. ॆిใࠂ͞Μ #BUUFSFDFJWFS w όοςϦʔϞχλʔ ϢʔςΟϦςΟʔ  w ࠷େ୆ ࣮ػ ϦϞʔτ୆

     w ख࣋ͪͷJ1IPOF͔Βଞʹ͍࣋ͬͯΔ J1IPOF J1BEͳͲͷػثͷόοςϦʔঢ়ଶ֬ ೝՄೳ w ࣗ୐ʹ͋ΔJ1IPOFͷόοςϦʔঢ়ଶ֬ೝՄ ೳ
  2. ॆిใࠂ͞Μ #BUUFSFDFJWFS w "QQMF8BUDIରԠ w $PNQMJDBUJPOTରԠ w ॆి׬ྃ௨஌ w ॆి׬ྃΛ఻͑ͯ͘ΕΔ௨஌Λ௥Ճ

    w ҎԼʹࢦఆ͢Δ͜ͱͰόοςϦʔ ΛέΞ͢Δ͜ͱ͕Մೳ w Կ͔ͱߴ͍J1IPOFΛ௕࣋ͪͤ͞Δͷʹ༗ ༻
  3. "QQ%FMFHBUFͷ੹຿ Ћ w ΞϓϦͷΤϯτϦʔϙΠϯτ &OUSZ1PJOU  w ΞϓϦΠϕϯτͷัଊ "QQMJDBUJPO&WFOU 

    w ը໘ͷߏங 4DSFFO#VJME  w ЋϚϧνϓϥοτϑΥʔϜԽ .VMUJQMBUGPSN
  4. &OUSZ1PJOU 0CKFDUJWF$ J04 J04 J04 NBJON "QQ%FMFHBUFI "QQ%FMFHBUFN "QQ%FMFHBUFTXJGU "QQ%FMFHBUFTXJGU

    4DF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{ @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene { WindowGroup { Text("͜ͷը໘͸Ұ࣌తͳ΋ͷͰ͢") .padding() } } }
  9. 4DFOF%FMFHBUFಠಛͳهड़ᶄ import UIKit class AppDelegate: UIResponder, UIApplicationDelegate { // MARK:

    UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { } } "QQ%FMFHBUFͰͷ4DFOFੜ੒Πϕϯτίʔυ
  10. 4DFOF%FMFHBUFಠಛͳهड़ᶅ import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { func scene(_

    scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { } func sceneDidDisconnect(_ scene: UIScene) { } func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { } } γϣʔτΧοτΠϕϯτΛิ଍͢Δ4DFOF%FMFHBUFͷίʔυ