[Xcode10 实际操作]一、博主领进门-(15)读取当前应用的信息

本文将演示读取当前应用的配置信息。

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

 1 import UIKit
 2 
 3 class ViewController: UIViewController {
 4 
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8         //获得当前可执行文件所在目录
 9         let mainBundle = Bundle.main
10         //获得程序包的识别标识符。
11         //该标识符是应用程序的唯一标识,应用程序和标识符之间是一一对应关系。
12         //请注意:应用程序创建成功后,该标识符将不可修改。
13         let identifier = mainBundle.bundleIdentifier
14         //获得应用程序的多有配置信息并存储在字典对象中
15         let info = mainBundle.infoDictionary
16         //获得当前应用程序的名称
17         let bundleId = mainBundle.object(forInfoDictionaryKey: "CFBundleName")
18         //获得当前应用程序的版本号
19         let version = mainBundle.object(forInfoDictionaryKey: "CFBundleShortVersionString")
20         
21         //在控制台打印输出相关日志
22         print("[identifier]:\(identifier!)")
23         print("[info]:\(info!)")
24         print("[bundleId]:\(bundleId!)")
25         print("[version]:\(version!)")
26     }
27 }

猜你喜欢

转载自www.cnblogs.com/strengthen/p/10125789.html