在Swift中获取构建日期和时间 [英] Get build date and time in Swift

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

问题描述

我在Objective-C中使用__DATE____TIME__来获取应用程序的构建日期和时间.我找不到在Swift中获取此信息的方法.有可能吗?

I'm using __DATE__ and __TIME__ in Objective-C to get the build date and time of my app. I can't find a way to get this information in Swift. Is it possible?

推荐答案

您可以使用#line#column#function.

原始答案:

在您的项目中创建一个新的Objective-C文件,当Xcode询问时,对创建桥接标头说是.

Create a new Objective-C file in your project, and when Xcode asks, say yes to creating the bridging header.

在这个新的Objective-C文件中,添加以下.h文件:

In this new Objective-C file, add the following the the .h file:

NSString *compileDate();
NSString *compileTime();

并在.m中实现以下功能:

NSString *compileDate() {
    return [NSString stringWithUTF8String:__DATE__];
}

NSString *compileTime() {
    return [NSString stringWithUTF8String:__TIME__];
}

现在转到桥接标题并导入我们创建的.h.

Now go to the bridging header and import the .h we created.

现在返回您的任何Swift文件:

Now back to any of your Swift files:

println(compileDate() + ", " + compileTime())

这篇关于在Swift中获取构建日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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