備忘録。ログインしていない状態の時には登録画面に遷移するなどにも応用できます。
##application(_:didFinishLaunchingWithOptions:)にUserDefaultsを設定する
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let userDefaults = UserDefaults.standard
let firstLunchKey = "firstLunchKey"
let firstLunch = [firstLunchKey: true]
userDefaults.register(defaults: firstLunch)
return true
}
##起動画面のViewDidAppeearにUserDefaultsを設定する
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let userDefaults = UserDefaults.standard
let firstLunchKey = "firstLunchKey"
if userDefaults.bool(forKey: firstLunchKey) {
performSegue(withIdentifier: "遷移させたい画面へのsegue.identifier", sender: self)
}
}