PearComp |
Pear Computer LLP is a fresh mobile software company from Cambridge, UK. We create usable and beautiful iPhone apps, like Cosmo Kid 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