NSDate (Helper)

2009-03-10 20:00:00 -0400

codebook datelabels

I saw Matt Drake’s post with tips about using NSDate over on Mobile Orchard’s iPhoneFlow today and figured I’d give the drummer some more.

When setting up Codebook (a secure notebook iPhone app we hope to release soon) I needed to do some fancy-pants date formatting all over the place because I wanted to mimic what Apple had pulled off in the Notes application for iPhone. Now, there are many ways to do this, I’m sure I’ve overlooked some useful tricks that Cocoa provides (it has a number of default date format “styles” you can use), but I think what’s important is to always avoid repeating yourself. And to do it in such a way that if, say, I realize that I really should have used the Cocoa candies, I could change the implementation in one place and the rest of my code would be none the wiser. DRY, as it were.

Now date calculations in Cocoa can be nasty. I don’t know if they have to be, but you can end up with a real mess of code involving NSCalendar, NSDateFormatter objects, or calculating offsets by seconds. Totally ugly.

Objective-C’s categories are a really nice way to bottle up some of this code and re-use it. In Codebook I used categories to implement helper methods on built-in objects and classes, like NSDate. So in the aforementioned example of Codebook, I implemented a series of methods for doing date calculations, and convenient methods for getting calculation-based formatted dates. Wrapping them up in NSDate (Helper) allows me to do things in the app like:

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

// figure out date display data at top of view
NSDate *relativeTime = (!targetObject.timestamp) ? [NSDate date] : [targetObject date];
dateLabel.text = [NSDate stringFromDate:relativeTime withFormat:@"MMM d"];
timeLabel.text = [NSDate stringFromDate:relativeTime withFormat:@"h:mm a"];
daysAgoLabel.text = [relativeTime stringDaysAgo];


The really tricky part on the notes listing was getting the conditional display like ‘11:59pm’ for an entry updated today, ‘Friday’ for a date within the last 7 days, ‘Jan 23’ for a date in the current calendar year, and ‘Nov 16, 2008’ for dates not in the current calendar year. And how simple is it now?

self.dateLabel.text = [NSDate stringForDisplayFromDate:date];

This gives us:

Codbook Minutemen

I have posted NSDate+Helper on Github, anybody is welcome to use it, fork it, add things, send pull requests. I bet we could build up a nice library of these guys for use in our applications.


Zetetic is the creator of the encrypted iPhone data vault and password manager Strip and the open source encryption-enhanced database engine SQLCipher.

And we're off!

2009-03-09 20:00:00 -0400

So today the Strip beta has actually kicked off! We got the last few UDID’s that were sent to us into the mobile provisioning profile, and blasted out a link to download everything with instructions to everyone who signed up. Thanks for waiting!

Apple has made this process – using Ad Hoc provisioning to beta test your app – an incredible time sink. In other words, really expensive. You can get a sense of the process over here.

For those of you who didn’t get a UDID in to us already, send it in, I think we should be able to get you into the next round of provisioning and we’ll re-issue the profile with the next version of the beta once we’ve had a chance to take a look at everyone’s feedback and fix any issues that stand out.

So, please send us your feedback to support@zetetic.net, we’re really looking forward to it!

Hang Tight

2009-03-08 20:00:00 -0400

A few folks have asked us what’s happening with the Strip beta. We’re almost finished provisioning all the Ad Hoc profiles. Don’t worry about what this means, other than it’s unbelievably annoying crap that Apple makes us do so we can have beta testers without making you pay for the app. Feel free to write them a strongly-worded letter!

Other things to read while you wait:

  • Unspace has opened up registration for their follow-up conference to RubyFringe: FutureRuby (Stephen and I will be attending!)
  • The AppleiPhoneApps.com folks coin the term Pocket Rejection, which I think is very clever if depressing.
  • Geithner out by June?


2009-03-05 19:00:00 -0500

STRIP isn’t the only iPhone application we’ve been working on. Can’t really go into the details right now, but I just wanted to give a heads up:

Codebook Promo

Strip Beta List

2009-03-01 19:00:00 -0500

Strip Icon We’re getting the beta email list together for Strip on the iPhone, we’ll be announcing the details shortly. If you want to participate, please shoot us an e-mail at support@zetetic.net. For those who aren’t hip with it just yet, Strip is our personal information and password manager. It stands for Secure Tool for Recalling Important Passwords, and you can read more about it over here.

Thanks for your patience while we’ve been getting the app together. It’s basically all set to go, but needs some user-vetting, and we need to spend a little time cranking out some utilities to migrate Palm Strip users to the new app (or to at least give them a CSV they can use to migrate to another platform).

And now I leave you with the Moz, got work to do: