0

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!

5
  • 1
    Are you building an .app bundle, or a command line tool? Did you specify the Info.plist file (Xcode does this by default when creating new app). Commented Sep 9, 2021 at 14:56
  • I am building a command line tool Commented Sep 9, 2021 at 14:57
  • That's the cause of your problem, command line apps consist just the executable, while app bundles (.app) are actually directories containing the executable, and the Info.plist file (among others). Commented Sep 9, 2021 at 14:59
  • 2
    See this: stackoverflow.com/q/55518922/1187415 and this: stackoverflow.com/q/7797773/1187415 about how to embed an Info.plist in a command line tool. Commented Sep 9, 2021 at 15:00
  • post your real code import foundation ??? Commented Sep 9, 2021 at 15:09

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.