0
votes

Main.Bundle.Infodidictionner le rendement du dictionnaire vide

Dans mon projet, j'ai un module séparé pour le code de réseau où je dois définir le numéro de version de l'application dans l'en-tête de chaque requête.

lors de l'appel d'initalisation de la notaireManager bundle.main.infodidictionner? ["CFBundleshORTVERINGSTRING"] car l'info-syndical est vide, bien que le paquet principal soit chargé.


0 commentaires

4 Réponses :


0
votes
if let version = Bundle.main.infoDictionary?["CFBundleVersion"] as? String {
    print(version)
}
You can try this.

0 commentaires

0
votes

Vous pouvez utiliser l'extension suivante

Bundle.main.versionNumber


0 commentaires

2
votes

Essayez ceci:

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


0 commentaires

-1
votes

Il y a un accesseur maintenant, "Objet (ForinfoDictionardictionGeyKey :()" Ce qui vous donne ceci:

if let version = Bundle.main.object(forInfoDictionaryKey:"CFBundleShortVersionString") as? String {
  print(version)
}


0 commentaires