Sorting an Array
Hi,
Create an Array use
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:2];
Let us suppose we have a class called Artist with a property artistName. artistName is also the key when implementing the get and the set methods.
To learn more about key-value programming go here
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/KeyValueCoding.html
Artist *object1 = [[Artist] alloc] init];
object1.artistName = @"Two";
Artist *object2 = [[Artist] alloc] init];
object2.artistName = @"One";
Add some objects to the array like this
[array addObject

bject1];
[array addObject

bject2];
Now to sort the array we will use NSSortDescriptor class like this
NSSortDescriptor *nsd = [[NSSortDescriptor alloc] initWithKey

"artistName" ascending:YES];
Add the Sort Descriptor class in an array
NSMutableArray *nsdArray = [[NSMutableArray alloc] init];
[nsdArray addObject:nsd];
Now you are ready to sort the array using sortUsingDescriptor method, like this
[array sortUsingDescriptors:nsdArray];
Your array will be sorted after the above line is executed.
To remove duplicates you can use removeObjectIdenticalTo or
filterUsingPredicate. You will need to create an object of NSPredicate but it uses teh same concepts of key-value programming.
To learn more about iPhone SDK, please visit
http://www.iphonesdkarticles.com
Thanks
iPhone SDK Articles