application welcome on first startup hello on next startup. I tried using Scene Delegate UserDefaults but I can only print in console because I don't know exactly.
I want the SplashViewController GreetingLabel section to write hello on the first startup of the application and welcome on the next startup, how can I do this?
two screen splash screen and main screen
Scene Delegate
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")
if launchedBefore {
print("Hello")
} else {
print("Welcome!")
UserDefaults.standard.set(true, forKey: "launchedBefore")
}
}
SplashController
class SplashViewController: UIViewController {
@IBOutlet weak var greetingLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
self.performSegue(withIdentifier: "splashToMain", sender: nil)
}
}
}