PearComp |
Pear Computer LLP is a fresh mobile software company from Cambridge, UK. We create usable and beautiful iPhone apps, like KashFlow and MyGas. We can also help you and your business to turn your app idea into reality. |
I decided to do the good deed of the day and migrate the first of the Objective-C blog posts from the old godawful site to our new one, as some people seemed to find these tutorials quite handy. This one’s called NSArray+UniqueObjects, and I hope you find it useful.
How does one get rid of duplicate values in an NSArray whilst maintaining a specified sort order? After researching the Cocoa documentation I couldn’t find a way to doing this with a oneliner. So here’s a category on NSArray that does it! The following code should help you out.
Here’s the header and implementation:
You can also grab the source code for this snippet from github:
git clone git://gist.github.com/339644.git gist-339644
Every iPhone developer wants to know how his apps are doing. While Apple tells you about sales and traffic, you can’t really compare your app to the competition. Although this information is available in iTunes in the form of a “ranking” of the top 100 applications in each category, there is no way of getting to it other than clicking through all the pages in iTunes by hand. What makes things worse is that there are many stores, and the rankings will be different in each store and category.
Not too long ago, Ben Chatelain wrote a perl script, based on Erica Sadun’s previous work, to exctract the rankings for an app identified by its ID from any iTunes Application Store in the world. Unfortunately, it seems that Apple keeps changing the XML format that these web services return. The original Perl script by Ben was subsequently modified by the guys at touchcentric to make it faster and easier to use.
Last week I downloaded the perl script from their website and tried to get statistics for our new app, Point Don’t Shout. As it turned out, the script didn’t work for me. I traced it down to the regular expression that digests the XML returned by Apple and extracts an app’s rank, id and name. It seems that Apple was kind enough to change their format, once again.
I set out to fixing this issue and modified the Perl script again. However, as the format has become more complicated, I decided to properly parse the XML using XML::TreeBuilder, a nice and simple XML DOM style parser for Perl. I also cleaned up the code and removed some unused functions as well as modifying the way caching was handled previously.
The new script can be downloaded here. Please let me know if you run into problems, or if you are overjoyed to use this little piece of code.