I am trying to find a way in Swift to detect the first launch.
Typically you would write a value to NSUserDefaults to indicate that an app has launched before.
let launchedBefore = NSUserDefaults.standardUserDefaults().boolForKey("launchedBefore") if launchedBefore { print("Not first launch.") } else { print("First launch, setting NSUserDefault.") NSUserDefaults.standardUserDefaults().setBool(true, forKey: "launchedBefore") }
UPDATE - Swift 3
let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore") if launchedBefore { print("Not first launch.") } else { print("First launch, setting UserDefault.") UserDefaults.standard.set(true, forKey: "launchedBefore") }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With