我正在尝试在我的个人图书馆中打印出一系列类型。我遇到了一个很大的问题,我无法得到这些类型的实际名称。
我的代码是:
// 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>])
如何让这些值等同于实际的流派名称?
答案 0 :(得分:1)
Here是MPMediaItemCollection
的文档,它是query.collections
中存储的对象。
每个MPMediaItemCollection
都有items
属性,这是MPMediaItem
s的数组。每个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
// ...
}
}