Get build date and time in Swift

前端 未结 3 477
温柔的废话
温柔的废话 2020-12-17 16:21

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. I

3条回答
  •  时光说笑
    2020-12-17 16:55

    You can use #line, #column, and #function.


    Original answer:

    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())
    

提交回复
热议问题