Skip to content

Instantly share code, notes, and snippets.

@feihong
Last active October 24, 2016 21:21
Show Gist options
  • Save feihong/2cb429c091126dc710b6 to your computer and use it in GitHub Desktop.
Save feihong/2cb429c091126dc710b6 to your computer and use it in GitHub Desktop.
Swift snippets

Print the names of all playlists:

import MediaPlayer

func printPlaylists() {
    let query = MPMediaQuery.playlistsQuery()
    print("Inside printPlaylists()")
    guard let result = query.collections else {return}
    print("Number of playlists: ", result.count)
    for playlist in result {
        let name = playlist.valueForProperty(MPMediaPlaylistPropertyName)!
        print("\(name), \(playlist.count)")
    }
}

// Running this in a playground doesn't print anything interesting.
printPlaylists()
@chauhan130
Copy link

This returns playlist directories as well, any idea how to filter those out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment