David Potter David Potter - 1 year ago 530
Swift Question

Get build date and time in Swift

I'm using

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?

Answer Source

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

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

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

And in the .m implement these functions:

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

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

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

Now back to any of your Swift files:

println(compileDate() + ", " + compileTime())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download