1

我正在尝试打印我个人图书馆中的流派列表。我遇到了一个巨大的问题,我无法获得这些流派的实际名称。

我的代码是:

// Initialization: 
let query = MPMediaQuery()

let result = query.items
print("count:  \(result?.count)") //This returns the amount of items in my library

现在这里是问题所在:

query.groupingType = MPMediaGrouping.genre 
var genreArray = query.collections
print(genreArray)

当我去打印它时,它给了我一个MPConcreteMediaItemCollection带有十六进制的项目列表:

<MPConcreteMediaItemCollection: 0x1c00cbf30>, <MPConcreteMediaItemCollection: 0x1c00cbfa0>, <MPConcreteMediaItemCollection: 0x1c00cc010>, <MPConcreteMediaItemCollection: 0x1c00cc080>, <MPConcreteMediaItemCollection: 0x1c00cc0f0>, <MPConcreteMediaItemCollection: 0x1c00cc160>, <MPConcreteMediaItemCollection: 0x1c00cc1d0>, <MPConcreteMediaItemCollection: 0x1c00cc240>, <MPConcreteMediaItemCollection: 0x1c00cc2b0>, <MPConcreteMediaItemCollection: 0x1c00cc320>, <MPConcreteMediaItemCollection: 0x1c00cc390>, <MPConcreteMediaItemCollection: 0x1c00cc400>, <MPConcreteMediaItemCollection: 0x1c00cc470>, <MPConcreteMediaItemCollection: 0x1c00cc4e0>, <MPConcreteMediaItemCollection: 0x1c00cc550>, <MPConcreteMediaItemCollection: 0x1c00cc5c0>, <MPConcreteMediaItemCollection: 0x1c00cc630>, <MPConcreteMediaItemCollection: 0x1c00cc6a0>, <MPConcreteMediaItemCollection: 0x1c00cc710>, <MPConcreteMediaItemCollection: 0x1c00cc780>, <MPConcreteMediaItemCollection: 0x1c00cc7f0>, <MPConcreteMediaItemCollection: 0x1c00cc860>, <MPConcreteMediaItemCollection: 0x1c00cc8d0>, <MPConcreteMediaItemCollection: 0x1c00cc940>, <MPConcreteMediaItemCollection: 0x1c00cc9b0>, <MPConcreteMediaItemCollection: 0x1c00cca20>, <MPConcreteMediaItemCollection: 0x1c00cca90>, <MPConcreteMediaItemCollection: 0x1c00ccb00>, <MPConcreteMediaItemCollection: 0x1c00ccb70>, <MPConcreteMediaItemCollection: 0x1c00ccbe0>, <MPConcreteMediaItemCollection: 0x1c00ccc50>, <MPConcreteMediaItemCollection: 0x1c00cccc0>, <MPConcreteMediaItemCollection: 0x1c00ccd30>, <MPConcreteMediaItemCollection: 0x1c00ccda0>, <MPConcreteMediaItemCollection: 0x1c00cce10>, <MPConcreteMediaItemCollection: 0x1c00cce80>, <MPConcreteMediaItemCollection: 0x1c00ccef0>, <MPConcreteMediaItemCollection: 0x1c00ccf60>, <MPConcreteMediaItemCollection: 0x1c00ccfd0>, <MPConcreteMediaItemCollection: 0x1c00cd040>, <MPConcreteMediaItemCollection: 0x1c00cd0b0>])

我如何让这些值等同于实际的流派名称?

4

1 回答 1

1

是 的文档MPMediaItemCollection,它是存储在query.collections.

每个MPMediaItemCollection都有一个items属性,它是一个MPMediaItems 数组。每个MPMedaItem人都有一个genre属性,这是您正在寻找的。

如果您查询的谓词是按流派,那么您可以说:

for collection in query.collections {
    let genre = collection.representativeItem?.genre
    // ...
}

否则,您将不得不遍历每个项目:

for collection in query.collections {
    for item in collection.items {
        let genre = item.genre
        // ...
    }
}
于 2018-02-08T21:28:44.690 回答