Question

MPMediaPropertyPredicate *titlePredicate = [MPMediaPropertyPredicate predicateWithValue:searchText 
                                                                            forProperty:MPMediaItemPropertyTitle
                                                                         comparisonType:MPMediaPredicateComparisonContains];
NSSet *predicateSet = [NSSet setWithObject:titlePredicate];
MPMediaQuery *searchQuery = [[MPMediaQuery alloc] initWithFilterPredicates:predicateSet];
NSArray *queryResults = [searchQuery items];

Im using the above code to return an array of MPMediaItems from the iTunes library where the song title matches searchText. However I would like it to match without punctuation, so that for example, songs with "Don't" in the title match "dont".

Thanks.

Was it helpful?

Solution

There's no built-in way. You'd have to change "dont" in the searchText to "don't" yourself. Or, at the expense of some speed, you could fetch all the titles of all the media items and enumerate them yourself; for example, once they were all in an NSArray you could call indexesOfObjectsPassingTest: and at that point your block can perform any test you like.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top