预处理器时间戳

Eri*_*ner 1 c xcode cocoa objective-c

是否可以通过预处理器宏生成嵌入式Unix时间戳?

例如: #define VERSION_EXPIRE __TIMESTAMP__

原因是,我有beta版本,我想在编译时生成一个过期时间戳(在特殊的构建配置中).

Eri*_*ner 6

我解决了它如下:

#define VERSION_TIMESTAMP __DATE__" "__TIME__"\x0"
Run Code Online (Sandbox Code Playgroud)

在其他一些班级

+ (NSDate *)versionExpiresInDays:(NSUInteger)days {
    NSString *dateString = [NSString stringWithUTF8String:VERSION_TIMESTAMP];   
    NSLocale *enLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
    NSDate *compiledOn = [NSDate dateWithNaturalLanguageString:dateString locale:enLocale];

    return [compiledOn dateByAddingTimeInterval:days*24*60*60];
}
Run Code Online (Sandbox Code Playgroud)