Google Data Framework for Cocoa

April 18, 2007

Some good news this week for Cocoa developers. Greg Robbins at Google recently released an Objective-C framework that allows you to use the APIs for Google Calendar, Google Base, Google Spreadsheets and others in an application, without having to worry too much about what’s going on behind the scenes.

It seems to me like this will greatly reduce the barrier of entry for anyone who’s been thinking of a neat way to integrate with a Google app, but doesn’t want to spend the time tying Cocoa together with the online APIs. I can certainly think of a few ideas I might like to play around with this summer.

Separate date and time components in NSDate

April 07, 2007

Cocoa makes it easy to bind an NSDate object to an NSTextField, allowing the user to view a date and time without writing any code for formatting or validation. As is often the case though, this doesn’t always exactly fit with what we want to achieve. There are situations where the user might want to change the date or the time, but not both; when you design your UI, the best choice would be to use two text field controls, one for the time, and one for the date.

You can bind two NSTextFields to a single NSDate, and by carefully tweaking the NSDateFormatters you can make one display only the time, and the other display the date. It’s not quite that simple though; when you change the date, it also changes the time to 12:00, even though it’s not shown in the control. As a quick fix you could just add a second NSDate to your class, but that’s just being lazy. Don’t be lazy!

One of the big secrets to Cocoa bindings is that when you bind something to a value, you don’t actually have to bind it to a value. Confused? Remember, when you bind a control to an object in Interface Builder (let’s say, bind a text field to the variable someDate) you’re not actually binding it directly to that object, you’re binding it to the KVO compliant accessor / mutator that provide access to the variable. This provides a perfect place to manipulate the object in question, and that’s just what we’re going to do.

Let’s assume we have a simple class that holds an NSDate instance variable named “start”. We’re going to add two new accessor and mutator methods, one for the time and one for the date.

- (NSDate *)startTime;
{
    return [self start];
}

- (NSDate *)startDate;
{
    return [self start];
}

- (void)setStartTime:(NSDate *)date;
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit ) fromDate:[self start]];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:date];

    [dateComponents setHour:[timeComponents hour]];
    [dateComponents setMinute:[timeComponents minute]];
    [dateComponents setSecond:[timeComponents second]];

    [self willChangeValueForKey:@"start"];
    NSDate *newDate = [calendar dateFromComponents:dateComponents];
    [self setStart:newDate];
    [self didChangeValueForKey:@"start"];
}

- (void)setStartDate:(NSDate *)date;
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[self start]];
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit ) fromDate:date];

    [timeComponents setYear:[dateComponents year]];
    [timeComponents setMonth:[dateComponents month]];
    [timeComponents setDay:[dateComponents day]];

    [self willChangeValueForKey:@"start"];
    NSDate *newDate = [calendar dateFromComponents:timeComponents];
    [self setStart:newDate];
    [self didChangeValueForKey:@"start"];
}

This looks a little complicated at first, but it’s actually very simple. The accessor methods startTime and startDate just return the start instance variable. Since NSDateFormatter knows how to show only the date or time parts of an NSDate (once you configure it in Interface Builder), it doesn’t matter that we’re providing it with both.

The mutator methods are where things get a little tricky. We’ll need to use the NSDateComponents class, which lets us pick and choose where each time and date component comes from; either the original NSDate, or the new NSDate from the NSTextField. We use the NSCalendar class to get these components, to ensure things like local daylight savings time values are taken into account.

Once we build the correct NSDate, it’s simple to update our class variable. Just make sure to call willChangeValueForKey and didChangeValueForKey, so any bound objects will be updated.

You can put these methods in the object itself, or if you really believe in the MVC way of doing things you can just make a category for them to completely separate the data from the interface.

Merchant Services Comparison

April 03, 2007

One of the things I’ve been doing as I get ready to sell Runner’s Log is choosing a payment processing system. Since my expected sales don’t justify the cost and time of using a dedicated credit card gateway, I’m looking at services like Paypal, Google Checkout and Kagi, among others.

Doing some reading yesterday, I found a PDF from Global Talk Software comparing the popular options for OSX shareware developers. There’s plenty of good information, including estimated costs and income for different levels of pricing. It’s very useful stuff for anyone interested in selling a software product online.

If you’re in the same position, make sure you look closely at the technical details before you choose a service provider. Google Checkout, for instance, has very good pricing, but requires SSL encryption on your website to receive sales notifications (which you need if you want to automatically generate a license key for each sale). Since the payment details are handled on the providers side of things, there’s no other reason to have SSL encryption enabled on your site, and with other providers like Paypal you don’t need it at all. Purchasing an SSL certificate just to work with Google Checkout could end up costing you more than choosing another provider, even if they do have higher fees per sale.

Runner’s Log Beta 3

March 31, 2007

The third beta of my new application, Runner’s Log, is now available. Beta 3 includes many new features and bug fixes, including some graphing features which are especially useful. Here’s a screenshot from the new version:

Runner’s Log Beta 3

More information and download links are here.

Windows Vista activation DNS bug (error 0x8007232b)

March 15, 2007

One of the nice things about having a Software Assurance subscription at work is that I have access to Windows Vista Enterprise, which comes with all sorts of goodies and can be downloaded straight from microsoft.com. Now, the way volume licensing is handled is completely different than it was in Windows XP, so I was a little concerned when I tried to activate Vista today and it complained about a DNS error, 0x8007232b.

After reading this thread, I found the solution. Right click on My Computer, select Properties, and click on Change product key at the bottom of the window. You’re then prompted to enter your key (I’m using MAK, but I assume KMS would work the same way), and Vista should connect to the internet and validate the key without any errors.

It’s a weird bug, and it seems like a lot of customers are running into it; not the type of thing I would expect to slip by QA. I hope it’s resolved by the time I start rolling out Vista to our users.

Auto-incrementing build numbers in Visual Studio

March 13, 2007

One neat feature in Visual Studio I came across today is auto-incrementing build numbers. You can use this to avoid having to configure or write an external tool or version control system just (although you should be using the latter anyway).

To enable it, just open AssemblyInfo.cs in your project, and change the AssemblyVersion setting to [assembly: AssemblyVersion( “1.0.*” )];. Remove the [assembly: AssemblyFileVersion( “1.0.0.0” )]; line entirely; it doesn’t support auto incrementing, and you usually don’t need it in the first place.

The next time you build your project, Visual Studio will put its own values in for the build number and revision number. It’s not too important how it generates these; but if you’re wondering, it uses the number of days since Jan. 1st 2000 as the build number, and the number of seconds since midnight number of seconds since midnight divided by 2 as the revision.

RSS in Outlook 2007, Pt. II

March 12, 2007

It looks like my initial optimism for RSS feeds in Outlook 2007 may have been a bit premature. I noticed last week that a few of my feeds weren’t updating (I actually noticed this with a few rarely updated feeds even longer ago, but when digg has no new stories, you know something is wrong). Send and receive didn’t report any errors, and it wasn’t until I looked at the account settings that I saw that some of my feeds weren’t listed anymore. Why, I have no idea. The mailbox folder (with the old news items) still existed, and I never saw any warnings or errors to indicate there might be a problem.

I could live with Outlook telling me it couldn’t update the feed, or the account settings were corrupted (or whatever actually happened, I’m just guessing), but when it quietly stops updating the feed, that makes me want to give it up altogether.

Update: I should have made it clear that this is under Windows XP. I recently installed Vista, which seems to have it’s own system-wide way of managing RSS feeds. Hopefully this will work a little better.

Palm hires ex-Apple engineer

March 09, 2007

From The New York Times:

SAN FRANCISCO, March 8 — Palm Inc., the maker of hand-held computers, has hired a top Silicon Valley software designer as it seeks to respond to the challenge posed by Apple’s new iPhone. The designer, Paul Mercer, a former Apple computer engineer, began work three weeks ago at Palm on a line of new products, a company spokeswoman said, but she declined to comment further on the project.

I’d love to see Palm make a comeback in the PDA and smartphone industry. I’ve bought mostly Compaq / HP’s Windows Mobile PDAs in the past, but I still can’t help but admire some of Palm’s hardware designs. Hopefully they’ll start showing some innovation in their software as well.

Juniper Networks Odyssey Access Client

March 02, 2007

WiFi support in Windows Mobile is horrible. I received an HP hx2495 recently, and I simply could not connect it to an encrypted wireless network, either at work or at home. I doubt it was anything wrong with the access points or a configuration issue; I’m very familiar with wireless security, and tried pretty much every possible configuration except for WEP.

Anyway, it so happens HP ships Odyssey Access Client on the extras CD with their higher-end line of PDAs. After finding and installing it, I had zero problems. WiFi at work and at home connected fine on the first try, even after enabling the highest security settings (WPA2 AES) on my access point. That’s surprising; even many PC laptops can’t do WPA2 reliably.

Odyssey Access Client is now owned by Juniper; you can find it here. Licenses are $50, but the cost is worth it, and I’m not aware of any other real competitor.

FreeBSD Setup: Install Perl

February 28, 2007

FreeBSD versions 5 and 6 no longer includes perl with the base system. That’s good and bad news for me, since I like the idea of a “stripped down” base system, but I do need perl for some of the software I’m planning on using.

It’s easy enough to install perl from the ports collection ((If you didn’t include the ports collection when you setup FreeBSD, get it now by running sysinstall and selecting ports from the Configure -> Distributions menu.)) though. Just run these commands:


cd /usr/ports/lang/perl5
make
make install
make clean

Keep in mind that this will install perl to /usr/local/bin/perl, rather than /usr/bin/perl as some scripts expect.

RSS in Outlook 2007

February 26, 2007

Ever since I started reading about Office 2007 I’ve been looking forward to the new RSS features in Outlook. Now that I’ve been using it for a few weeks, I’ve really grown to love it. As a newsreader there’s nothing special about Outlook (in fact, there are some things about it that are downright annoying), but what’s great is that each feed is stored as a regular Outlook mail message, in a regular Outlook mail folder.

If you have an Exchange account that you widely use, this is simply a great way to manage your feeds. Everything is stored under your Exchange mailbox, so you can use any computer with Outlook, even older versions. Same thing with Outlook Web Access, or syncing with your PDA, if you’re away from home. The only real downside is that you’ll have to leave Outlook 2007 open to actually refresh the feeds, since it’s the client generating them, and not the Exchange server itself.

Office 2008 Remote Desktop Client

February 22, 2007

It’s just a rumor at this point, but I have it on good authority the next version of Office for OSX will include a new, greatly improved Remote Desktop client. This is, of course, good news for anyone using the old RDC client, which hasn’t been updated since way back in 2004. Not that it doesn’t still work well enough, but it’s long overdue for an overhaul.