iosswiftxcodemodulensbundle

Main.bundle.infoDictionary returns me empty Dictionary


In my project I have a seperate module for networking code where I need to set the version number of the app in the header of each request.

During initalization call of the networkmanager Bundle.main.infoDictionary?["CFBundleShortVersionString"]since the infoDictionary is empty although the Main bundle is loaded.


Solution

  • Try this:

    let bundle = Bundle(for: type(of: self))
    if let version = bundle.infoDictionary?["CFBundleShortVersionString"] as? String {
            print(version)
    }