I would like to display a welcome screen when a user opens my app for the first time. What method is there to check the first launch of an app in Swift?
A slight semantic modification of Jonas Deichelmann's answer, clarifying a few things:
The print statements make clear that this function is only verifying if it has been run since last installation, not whether or not it has ever been run on this device.
func establishUserDefaultsHaveBeenVerifed()->Bool{
let defaults = UserDefaults.standard
if let _ = defaults.string(forKey: "userDefaultsHaveBeenVerified"){
print("user defaults were already verified")
return true
}else{
defaults.set(true, forKey: "userDefaultsHaveBeenVerified")
print("verified user defaults for first time since app was installed")
return false
}
}