I think, given answers are good when you've a small scale application but when you working on a large-scale iOS apps with a long roadmap you definitely need a strong futuristic solution with benefits like.
- Better compare logic that works fine with all possibilities (2.0/2.0.0 etc).
- Take specific action during migration, assume when user migratingfrom version 1.0 to 2.0 verses 1.1 to 2.0.
- Reset the cached version when the user reset the app (Logout).
Below is the code snippet that I used in one of my iOS App.
public enum VersionConfigResponse { case freshInstalled case versionGreater case versionEqualOrLesser case currentVersionEmpty}/* Config manager responsible to handle the change needs to be done when user migrate from one Version to another Version. */public class VersionConfig { public static let shared = VersionConfig() private init() { } private let versionKey = "SAVED_SHORT_VERSION_STRING" /* Cache the existing version for compare during next app launch. */ private var storedVersion : String? { get { return UserDefaults.standard.object(forKey: versionKey) as? String } set { UserDefaults.standard.set(newValue, forKey: versionKey) UserDefaults.standard.synchronize() } } /* Validate the current version with saved version, if greater do clean. */ public func validate(currentVersion: String?) -> VersionConfigResponse { guard let currentVersion = currentVersion else { return .currentVersionEmpty } guard let sVersion = storedVersion else { self.storedVersion = currentVersion self.freshInstalled() return .freshInstalled } if currentVersion.compare(sVersion, options: .numeric, range: nil, locale: nil) == .orderedDescending { self.storedVersion = currentVersion self.userMigrated(fromVersion: sVersion, toVersion:currentVersion) return .versionGreater } else { return .versionEqualOrLesser } } private func userMigrated(fromVersion: String, toVersion: String) { //take your action here... } private func freshInstalled() { //take your action here... } /* Remove saved version if user reset(logout) the app. */ public func reset() { self.storedVersion = nil }}//trigger version config with current versionVersionConfig.shared.validate(currentVersion: "1.0.0")//reset when user logsoutVersionConfig.shared.reset()