Search code examples
iosswiftmpmediaitemmpmediaqueryapple-music

How to access the "Sort as" field of MPMediaItem?


iTunes has a way of sorting the songs that the ones with title starts with "a" or "the" are recognized without it. Is there a way to access this "sort title"? I am pretty sure Apple Music does this and I guess it can be accessed by

let item = MPMediaItem()
let sortName = item.value(forProperty: "someMagicSortNamePropertyIdentifier") as! String

I am talking about this fields in iTunes enter image description here


Solution

  • Basic format for all sort Properties is sortProperty i.e. sortTitle, sortAlbumTitle, sortAlbumArtist etc.

    func sortProperty(for property: String) -> String{
        return "sort" + property.prefix(1).uppercased() + property.dropFirst()
    }