Skip to content

Instantly share code, notes, and snippets.

@Shinolr
Last active April 30, 2019 11:57
Show Gist options
  • Save Shinolr/76f9814954e9026ed247e7fef56adbc2 to your computer and use it in GitHub Desktop.
Save Shinolr/76f9814954e9026ed247e7fef56adbc2 to your computer and use it in GitHub Desktop.
Check app version, whether should load user guide
protocol AppGuide {
func shouldLoadAppGuide() -> Bool
}
extension AppGuide {
func shouldLoadAppGuide() -> Bool {
guard let versionString = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else {
return false
}
guard let currentVersion = Int(versionString) else {
return false
}
let lastVersion = UserDefaults.standard.integer(forKey: "CFBundleVersion")
guard currentVersion > lastVersion else {
return false
}
UserDefaults.standard.set(currentVersion, forKey: "CFBundleVersion")
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment