我想向 MPMediaQuery
添加一系列谓词,但我希望它使用 OR 而不是 AND 聚合:
MPMediaQuery *q = [MPMediaQuery songsQuery];
NSMutableArray *a = [@[] mutableCopy];
for (DFLocalMediaItem *item in self.offlineItems) {
MPMediaPropertyPredicate* p = [MPMediaPropertyPredicate predicateWithValue:item.identifier
forProperty:MPMediaItemPropertyPersistentID];
[a addObject:p];
}
NSSet *s = [NSSet setWithArray:a];
[q setFilterPredicates:s];
当我创建这个集合时,它使用 AND 聚合上面的 MPMediaPropertyPredicate
(这显然不会起作用..因为单个 MPMediaItem 显然有一个标识符)
想法?
最佳答案
由于公共(public) API,您无法拥有此类功能。 official docs说
When you apply more than one predicate to a query, the query combines them using the logical AND operator.
但是如果你想从你的项目中构建一个 MPMediaItemCollection,或者你可以从一个类似于 MPMediaQuery 结构的数组中构建,它具有相同的方法,但后面有静态数组。
关于ios - 如何创建一组由 OR 而不是 AND 连接的 MPMediaPropertyPredicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33761035/