Get unique artist names from MPMediaQuery
- by Akash Malhotra
I am using MPMediaQuery to get all artists from library. Its returning unique names I guess but the problem is I have artists in my library like "Alice In Chains" and "Alice In Chains ". The second "Alice In Chains" has some white spaces at the end, so it returns both. I dont want that. Heres the code...
MPMediaQuery *query=[MPMediaQuery artistsQuery];
NSArray *artists=[query collections];
artistNames=[[NSMutableArray alloc]init];
for(MPMediaItemCollection *collection in artists)
{
MPMediaItem *item=[collection representativeItem];
[artistNames addObject:[item valueForProperty:MPMediaItemPropertyArtist]];
}
uniqueNames=[[NSMutableArray alloc]init];
for(id object in artistNames)
{
if(![uniqueNames containsObject:object])
{
[uniqueNames addObject:object];
}
}
Any ideas?