使用Swift获取版本和构建信息 [英] Getting Version and Build Info with Swift

查看:185
本文介绍了使用Swift获取版本和构建信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访问Main NSBundle以检索版本和构建信息。事实是,我想在swift中尝试它,我知道如何在Objective-C中使用 Build.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@CFBundleVersion]; 。但我不知道从哪里开始使用swift,我试图用新的语法编写它,但没有用。感谢您的帮助!

I am attempting to gain access to the Main NSBundle to retrieve Version and Build information. Thing is, I want to try it in swift, I know how to retrieve it in Objective-C with Build.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];. Yet I don't know where to start with swift, I have attempted to write it in the new syntax with no avail. Thanks for any help!

推荐答案

Swift语法出了什么问题?这似乎有效:

What was wrong with the Swift syntax? This seems to work:

if let text = Bundle.main.infoDictionary?["CFBundleVersion"]  as? String {
    print(text)
}

这篇关于使用Swift获取版本和构建信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆