How to get app version and build number in Swift?
Hello everyone! I'm a beginner in Swift and writing my first iOS app. I need to display the current app version (e.g., "1.2.3") and build number (e.g., "45") on the settings screen. I know this information is stored in Info.plist, but I can't figure out how to properly extract it via code.
I tried using Bundle.main.object(forInfoDictionaryKey:), but I get nil or strange data types. For example, my code:
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")
print(version) // Prints Optional(1.0)
I also tried:
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")
print(build) // Prints Optional(1)
But when I try to cast the result to String, I get errors. Also, I've heard there is a more modern