Search code examples
iphoneiosmpmediaquery

search for iPod artists starting with a letter


Is there a way to use something like a wildcard character to search for all iPod artist names starting with a given letter, something like this:

MPMediaPropertyPredicate *artistNamePredicate = [MPMediaPropertyPredicate predicateWithValue:@"A*" forProperty:MPMediaItemPropertyArtist];

MPMediaQuery *allArtistsQuery = [MPMediaQuery artistsQuery];

[allArtistsQuery addFilterPredicate: artistNamePredicate];

Solution

  • MPMediaPropertyPredicate only supports the property value being equal to the predicate value (the default) or containing the predicate value, as noted in the docs.

    That being said, an alternative is to use the contains comparison and then filter the results with the returned values.

    [MPMediaPropertyPredicate predicateWithValue:@"A*" forProperty:MPMediaItemPropertyArtist comparisonType:MPMediaPredicateComparisonContains]