无法下标[MPMediaItem]类型的值 [英] cannot subscript a value of type [MPMediaItem]
问题描述
我正在尝试执行此代码,以获取用户可以在手机上拥有的所有音乐播放列表.
I am trying to execute this code in order to get all the music playlists that the users can have on their phones.
var queryPlaylists = MPMediaQuery.playlistsQuery()
print(queryPlaylists.collections[0])
但是,当我尝试访问queryPlaylists.collections的任何元素时,都会出现编译错误:
However, when I try to access any of the elements of queryPlaylists.collections I get a compilation error:
无法下标[MPMediaItem]类型的值.
Cannot subscript a value of type [MPMediaItem].
自从上面的数组以来,这对我来说没有任何意义.此外,该功能以前在xcode 7.0之前有效.
This does not make any sense to me since the above in an array. In addition this used to work before xcode 7.0.
推荐答案
我想出了要访问queryPlaylists中的元素的方法,您需要创建一个新变量并将其转换为
I figured out in order to access the elements in the queryPlaylists you need to create a new variable and cast it to [MPMediaPlaylist] as
var播放列表= queryPlaylists.collections为! [MPMediaPlaylist]
var playlists = queryPlaylists.collections as! [MPMediaPlaylist]
现在您可以访问播放列表的元素
now you can access the elements of playlists
这篇关于无法下标[MPMediaItem]类型的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!