Liang Wang
Posted on February 5, 2024
Previously I hardcoded the appVersion and put it into the constant file, but I keep forgetting to update it when I make a new build or update the version in the Settings.
Today I found out that there is a good question and answer from StackOverflow that fixes my problem programmatically, which is nice to have, as I am lazy to remember too much tiny stuff here and there.
Solution:
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
Example:
Text(appVersion ?? "Unknown version")
Tip: (also from the answers)
Be sure to not confuse CFBundleVersion
& CFBundleShortVersionString
.
The first is your build version.
The other is version number.
Posted on February 5, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 19, 2024