inessential by Brent Simmons


I’m working on a Cocoa class for reading RSS feeds. My intent is to make it open source (BSD license) so it’s available to other Cocoa developers. I chose the BSD license so people doing commercial apps can use it too.

Here’s what the API looks like. I’m seeking comments on its 1) Cocoa-ness and 2) usefulness.

initWithData (NSData) takes data and returns an RSS object.

initWithUrl (NSURL) takes a URL, gets it from the Web, then returns an RSS object. (It calls initWithData.)

lastReadDate returns an NSDate specifying when the RSS object was created (presumably when the data was last read).

version returns an NSString specifying the RSS version.

Here are the two interesting ones—the above are fairly non-controversial, I think.

headerItems returns an NSDictionary of all the stuff in the header: the title of the channel, webMaster, and so on.

itemsArray returns an NSArray of all the news items. Each item in the array is an NSDictionary containing the elements of the item: link, description, title, and so on.

I thought about normalizing headerItems and the items in itemsArray. What I mean is I thought about always having a ‘webMaster’ key in the headerItems dictionary even when that item didn’t appear in the RSS feed. (For instance.)

But I decided not to do any normalizing for these reasons:

1. Which spec would I normalize to? All of them? What about optional items? What about new specs that appear later on? In this case, normalization is what we doctors call a quagmire.

2. Normalization would remove potentially important information. You wouldn’t be able to tell the difference between an empty element and an element that wasn’t specified.

The downside is that anyone using an RSS object will have to check for existence. For instance, if you want to get the ‘link’ element of a news item, you can’t assume that the element exists. If it didn’t exist in the RSS feed, it won’t exist in the dictionary for that news item. But I think that’s okay.