Building expiring software

July 13, 2007

A neat pre-processor trick from Brian Cooke showed up on Daniel Jalkut’s blog today. It’s useful for anyone working with beta software that needs to expire after a certain date; instead of putting a new expiration date into your code each time you release a build, you use the gcc DATE macro.

// Two-week expiration

// Idea from Brian Cooke.
NSString* nowString =
[NSString stringWithUTF8String:__DATE__];
NSCalendarDate* nowDate =
[NSCalendarDate dateWithNaturalLanguageString:nowString];
NSCalendarDate* expireDate =
[nowDate addTimeInterval:(60*60*24* EXPIREAFTERDAYS)];

if ([expireDate earlierDate:[NSDate date]] == expireDate)
// Run an alert or whatever
// Quit!
[[NSApplication sharedApplication] terminate:self];

Again, thanks to Daniel Jalkut for writing up the explanation and code sample.

Marc Charbonneau is a mobile software engineer in Portland, OR. Want to reply to this article? Get in touch on Twitter @mbcharbonneau.