やりたいこと
swiftで一回目の起動と二回目の起動でアプリの起動画面を切り替えたい。
###やったこと
ネットでやり方を調べた。
該当のソースコード
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { if lanchIsFirstTime() { logFirstLanch() return true } if let window = self.window, let storyboard = window.rootViewController?.storyboard { window.rootViewController = storyboard.instantiateViewController(withIdentifier: "secondView") window.makeKeyAndVisible() } return true } private let STORED_KEY = "lanched" func logFirstLanch() { return UserDefaults.standard.set(true, forKey: STORED_KEY) } func lanchIsFirstTime() -> Bool { return !UserDefaults.standard.bool(forKey: STORED_KEY) }
補足情報(FW/ツールのバージョンなど)
Xcode11
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/11 08:44
2020/03/11 10:11
2020/03/12 02:08
2020/03/12 02:38