NnVersionKit is a lightweight Swift package for detecting app version changes. It helps compare the locally installed version of your app with the version available on the App Store, allowing you to prompt users for updates based on major, minor, or patch version differences.
This package is ideal for developers who want fine-grained control over version update logic in SwiftUI-based apps.
- Retrieve current app version from the local
Info.plist
- Fetch latest version info from the App Store
- Compare versions at major, minor, or patch level
- Async/await-powered version loading
- SwiftUI view modifiers to trigger update UIs
- Fully tested with lightweight, modern syntax
.package(url: "https://github.com/nikolainobadi/NnVersionKit", from: "1.0.0")
Just pass in the main Bundle
of your app to compare the device version with the current version from the App Store.
By default, the version number being compared will be the major number, but you can pass in a different VersionNumberType
if you want updates to trigger for minor or patch changes.
import NnVersionKit
var body: some View {
ContentView()
.checkingAppVersion(bundle: .main, versionNumberUpdateType: .major) {
Text("Please update the app!")
}
}
If you store your local device version outside of the main Bundle
, and/or your app isn't on the App Store (or you store the 'online version number' elsewhere), you can simply implement your own VersionLoader
s to pass into the view modifier.
let deviceLoader: VersionLoader // your custom implementation
let onlineLoader: VersionLoader // your custom implementation
var body: some View {
ContentView()
.checkingAppVersion(deviceVersionLoader: deviceLoader, onlineVersionLoader: onlineLoader) {
Text("Please update the app!")
}
}
Your custom implemntation would simply have to return a VersionNumber
to conform to VersionLoader
:
public protocol VersionLoader: Sendable {
func loadVersionNumber() async throws -> VersionNumber
}
For non-SwiftUI developers, you can use a default VersionLoader
combined with VersionNumberHandler
to compare versions manually.
let deviceVersionLoader = DeviceBundleVersionLoader(bundle: .main)
let onlineVersionLoader = AppStoreVersionLoader(bundleId: Bundle.main.bundleIdentifier)
let deviceVersion = try await deviceVersionLoader.loadVersionNumber()
let onlineVersion = try await onlineVersionLoader.loadVersionNumber()
let updateRequired = VersionNumberHandler.versionUpdateIsRequired(deviceVersion: deviceVersion, onlineVersion: onlineVersion)
print("version update required:", updateRequired)
Feel free to open an issue if you have any suggestions or feedback.
For larger changes, consider opening a discussion first.
This project is licensed under the MIT License. See the LICENSE file for details.