Search code examples
swiftplistversioning

Swift application has no version?


I am trying to get my app version, after following this I tried this code :

import foundation
var config: [String: Any]?

if let infoPlistPath = Bundle.main.url(forResource: "Info", withExtension: "plist") {
    do {
        let infoPlistData = try Data(contentsOf: infoPlistPath)
        
        if let dict = try PropertyListSerialization.propertyList(from: infoPlistData, options: [], format: nil) as? [String: Any] {
            config = dict
        }
    } catch {
        print(error)
    }
}

print(config?["CFBundleName"])
// Optional(example-info)

print(config?["CFBundleVersion"])
// Optional(1)

print(config?["CFBundleShortVersionString"])
// Optional(1.0)

but I get always nil as a result.

Does that mean that my app has no version? If so how to set a version to it?

In addition, when I investigate the Info.plist file with Xcode I found that it's empty!


Solution

  • Thanks to @Martin R is comment i solved my problem by linking a new plist file to the project