I've created BundleInfoVersioning
swift package to help me solve this issue.
It works with all keys in the info dictionary, like CFBundleVersion
or CFBundleShortVersionString
and with custom key paths like, for example, NSAgora/DatabaseVersion
.
Examples:
let bundleInfoVersioning = BundleInfoVersioning(bundle: .main)bundleInfoVersioning.check(forKeyPath: "CFBundleVersion") { (old: String?, new: String?) in if old == nil { Analytics.install(version: new) } else { Analytics.update(from: old, to: new) }}bundleInfoVersioning.check(forKeyPath: "CFBundleShortVersionString") { _ , newVersion in self.showWhatsNew(in: newVersion)}bundleInfoVersioning.check(forKeyPath: "NSAgora/DatabaseVersion") { (old: Int?, new: Int?) in self.resetDataBase()}
You can check it out on github at https://github.com/nsagora/bundle-info-versioning.