TouchCode Rocks

TouchCode is a set of iPhone open source projects that fill in some features that are missing from Cocoa Touch. The most useful part is TouchXML, which is a drop-in replacement for Cocoa’s NSXML* classes.

I was able to get the unmodified ObjectiveFlickr code working by simply doing a global search & replace of NSXMLDocument with CXMLDocument, NSXMLNode with CXMLNode, and NSXMLElement with CXMLElement. The result is less ugly than using NSXMLParser.

For the Official LOLCats application I need to handle RSS feeds, which I found to be exceptionally ugly with NSXMLParser. With TouchXML it’s easy. I can get an array of items with something like this:


NSError *err = nil;
CXMLDocument *doc = [[CXMLDocument alloc]
initWithContentsOfURL: [NSURL URLWithString: @"http://feeds.feedburner.com/myfeed"]
options:0 error: &err];

NSArray *nodes = [doc nodesForXPath: @"//item" error: nil];

Flickr Frameworks on the iPhone

I spent the weekend modifying ObjectiveFlickr to work on the iPhone, which was mostly a matter of changing the response handling code that depends on NSXMLDocument. I was pretty much able to plug in my MCFlickrParser class, which I use in LOLCats, to create a NSDictionary structured very much like the XML document.

Yesterday I was informed about FlickrKit, which already works on the iPhone. FlickrKit seems more advanced, but it’s also a lot larger than ObjectiveFlickr. I created simple Flickr browsers using both frameworks. The FlickrKit version is 704k, while the ObjectiveFlickr version is only 148k. I’ve only tried it on the simulator and the performance seems about the same for both.

I will probably stick with OF for this project, since I would like to support Zooomr as well as Flickr and OF already seems to support Zooomr.

LOLCats 1.1 is available

UPDATE: Minutes after I posted this, I got a notice from Apple that the update has been approved and is now ready for sale.

Apple still hasn’t approved my update to LOLCats. Still no response from Apple for the second update, which I feel is pretty urgent, since it reduces the possibility of inappropriate images appearing, which I’ve received several complaints about.

I’m now getting close to another update, which adds Zooomr support.

Meanwhile, I’m working on a second Flickr-related application. I had expected to share a lot of code with LOLCats, but it turns out I’ve only reused one class, my Flickr parser.

For this app, I need to support Flickr authorization, so it seemed easier to rewrite Flickr’s ObjectiveFlickr code, which already supports authorization. However, ObjectiveFlickr depends on XMLDocument, which isn’t available on the iPhone. I’m replacing the response handling code with my Flickr parser class. When it’s finished, I’ll release the Flickr-related code (not the entire app) as open source.

On a fun note, I purposely added the LOLCATS tag to this photo of Midnight to make it to appear in the application. As a result, the number of hits on that photo are about 100x the average for my similar photos.

Midnight watching

Zooomr supports Flickr API

Until I started poking around in Flickr’s Objective C code, I didn’t realize that Zooomr supported a variant of Flickr’s API. I found that it’s fairly easy to port code which uses Flickr to Zooomr. In less than an hour, I had LOLCats working with Zooomr. I plan to include Zooomr support in the other iPhone Flickr app I’m working on.

Setting up Subversion at MediaTemple

I recently moved my Subversion repositories from my home server to Dreamhost, for the extra safety of an offsite backup of my source code. When I switched this domain to MediaTemple it unsurprisingly broke my Subversion repository.

While DreamHost provides an easy one click Subversion setup, it requires a little more work on MediaTemple. After a few headaches, I managed to get it set up. I hope I can save some people a bit of trouble with these tips. This only applies to a GridServer. It will probably be different for other MediaTemple account types.

Unlike DreamHost, the GridServer doesn’t support HTTP access for Subversion; you can only use SSH. Note that your SSH login includes the domain name. The login will usually be serveradmin%yourdomain.com@yourdomain.com.

You’ll need to log in to your serveradmin account via ssh to create the repository. For best results, it should be in in the /data directory. After logging in, create the repository with the following commands:

cd data
svnadmin create --fs-type fsfs SVN

This will create a repository named SVN. You can use a different name if you prefer.

You can then set up the repository in XCode. Create a new repository configuration and enter a URL like svn+ssh://serveradmin%yourdomain.com@yourdomain.com/home/XXXXX/data/SVN. To find the actual path, when you’re logged in via ssh, enter the command pwd, which will give you something like /home/11111/users/.home. You can ignore the /users/.home part.

Be very careful to enter the login and password correctly. If you attempt too many incorrect logins, you will be locked out. To regain access, go to the Mediatemple control panel and click the button to unlock, and wait about 10 minutes.

SVN Setup
Uploaded with plasq‘s Skitch!

Another Photowalk

Paulo is planning another photowalk on August 23 in connection with Scott Kelby‘s Worldwide Photo Walk. This one will be in Lauderdale-by-the-sea, a quaint beach town only a few miles from me, at the end of Commercial Blvd. I’ve been there many times.

Cocoa debugging tip

When you’re debugging a memory allocation issue, it’s very useful to be able to see the retain count of an object. One way to do it is by calling the object’s retainCount method, which you can do in the debugger console by entering something like call (int)[self retainCount].

That’s a lot of typing if you do it very often. Fortunately GDB lets you create macros that can make it a lot easier. To define a macro called rc, which will print the retain count, you can define a macro as follows:

define rc
call (int)[$arg0 retainCount]
end

You can now type rc self to see the current object’s retain count. Unfortunately you’ll have to enter that definition every time you start the debugger.

However, GDB lets you create a startup file with commands that will be executed every time it starts up. Simply create a file called .gdbinit in your home directory and enter that definition in it. You will now have the command rc available every time you use the debugger.

Document-based vs. event-driven XML parsing

When I wrote my FriendFeed Cocoa classes, I used the document-based NSXMLDocument class, which I later found out isn’t available on the iPhone. However, there’s an alternative that’s available both in Mac OS X and the iPhone: NSXMLParser, which uses an event-driven approach.

While the two approaches are very different, I found that it isn’t too difficult to rewrite my code to use XMLParser. I’ve been working on a fun iPhone app using the Flickr API and I found that the event driven approach is very easy to use.

With NSXMLDocument, I called the parser and then iterated through the resulting collection of elements, creating my own objects from each element. With NSXMLParser, on the other hand, my callback methods get called for each element, which I can then use to create my own object in a very similar way. A single element with several attributes, such as Flickr’s response format, is very easy to deal with since it can be handled in its entirety with a single method. An element with child elements, such as FriendFeed uses, is only slightly more difficult. I need to use both the start element & end element methods for the parent element.

After I finish the Flickr app, I plan to rewrite my FriendFeed class to work on the iPhone.