Get unique artist names from MPMediaQuery
Posted
by
Akash Malhotra
on Stack Overflow
See other posts from Stack Overflow
or by Akash Malhotra
Published on 2012-03-30T05:25:24Z
Indexed on
2012/03/30
5:30 UTC
Read the original article
Hit count: 258
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?
© Stack Overflow or respective owner