使用不带标点符号的 MPMediaPropertyPredicate 的 MPMediaQuery
MPMediaPropertyPredicate *titlePredicate = [MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyTitle
comparisonType:MPMediaPredicateComparisonContains];
NSSet *predicateSet = [NSSet setWithObject:titlePredicate];
MPMediaQuery *searchQuery = [[MPMediaQuery alloc] initWithFilterPredicates:predicateSet];
NSArray *queryResults = [searchQuery items];
我使用上面的代码从 iTunes 库返回一个 MPMediaItems
数组,其中歌曲标题与 searchText
匹配。不过,我希望它在没有标点符号的情况下匹配,例如,标题中带有“Don't
”的歌曲匹配“dont
”。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内置的方法。您必须自己将
searchText
中的“dont”更改为“don't”。或者,以牺牲一定速度为代价,您可以获取所有媒体项的所有标题并自己枚举它们;例如,一旦它们全部位于 NSArray 中,您就可以调用indexesOfObjectsPassingTest:
,此时您的块可以执行您喜欢的任何测试。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 callindexesOfObjectsPassingTest:
and at that point your block can perform any test you like.