本文介绍了当专辑信息可用时,按专辑对歌曲数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用符合特定条件的歌曲填充数组.
I'm populating an array with songs that match a specific criteria.
NSArray *songs = [[[MPMediaQuery alloc] init] items];
NSMutableArray *filteredSongs;
for (int i=0; i<[songs count]; i++) {
// filter logic here: if songs[i] match the criteria, push it filteredSongs array
}
现在,我想按 MPMediaItemPropertyAlbumTitle
对该数组进行排序,但是如果缺少用户mp3的专辑信息,可以避免出现问题.(我试图在此处)找到解决问题的解决方法
Now I'd like to sort that array by MPMediaItemPropertyAlbumTitle
, but avoiding problems if the Album info of the user's mp3 is missing.(I'm trying to find a workaround for the problem solved here)
推荐答案
您可以使用 NSComparisonResult 可以按专辑标题排序.这应该处理nil albumTitle值,并将它们推回到后面.
You can use the NSComparisonResult to sort by album title. This should handle nil albumTitle values and push them to the back.
[songs sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
return [[obj2 albumTitle] compare:[obj1 albumTitle]];
}];
这篇关于当专辑信息可用时,按专辑对歌曲数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!