我正在用符合特定条件的歌曲填充一个数组。
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 的专辑信息丢失,则可以避免出现问题。
(我正在尝试找到解决问题的解决方法 here )
最佳答案
您可以使用 NSComparisonResult按专辑标题排序。这应该处理 nil albumTitle 值并将它们推到后面。
[songs sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
return [[obj2 albumTitle] compare:[obj1 albumTitle]];
}];
关于ios - 当专辑信息可用时,按专辑对歌曲数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21609105/