How to manage playlists using Spotify SDK for iOS with Swift 5

I’m working on an iOS app and need help with playlist management through the Spotify SDK. Specifically, I want to retrieve existing playlists, create new ones, and modify them using Swift 5. I’ve been using SPTAppRemote but I’m not sure if this is the right approach for playlist operations. The documentation seems limited and most of the solutions I found online are outdated. Can anyone point me in the right direction or share some working code examples for playlist manipulation with the current Spotify iOS SDK?

just hit this last month! make sure you handle oauth redirects correctly when switching between sptappremote and web api calls. i hardcoded my redirect uri and it broke everything. also, for large playlists, the api paginates results - you’ll need to loop through the ‘next’ urls to grab all tracks. took me hours to figure that out.

SPTAppRemote is primarily designed for controlling playback and does not facilitate playlist management. For handling playlists, you’ll want to utilize the Spotify Web API since the current iOS SDK lacks the necessary functionality. I encountered a similar challenge previously while developing an app. A practical approach is to use SPTAppRemote to authenticate and acquire your access token, and then make API calls to endpoints such as ‘/v1/me/playlists’ to retrieve playlists, ‘/v1/users/{user_id}/playlists’ to create new playlists, and ‘/v1/playlists/{playlist_id}/tracks’ to update tracks. It’s advisable to establish a dedicated network layer using URLSession for handling these API interactions. Additionally, ensure you manage token refresh appropriately and request the necessary scopes, like ‘playlist-modify-public’ and ‘playlist-modify-private’, when obtaining authorization. The Web API documentation is significantly more comprehensive compared to the iOS SDK documentation for these tasks.

Yeah, the combination approach is spot on, but here are some things I learned the hard way. You’ll need to juggle authentication carefully - the remote and web endpoints use different token scopes. I built a token manager class to handle both flows, which saved me tons of headaches. Watch out for playlist rate limits - you’ll hit 429 responses if you’re not careful, so build in proper error handling. Here’s a weird one: when you create a playlist, the API gives you the ID right away, but sometimes there’s a delay before you can actually add tracks to it. I throw in a small delay or retry when chaining playlist creation with adding tracks. Pro tip: use the Web API playground to test everything before coding it in Swift.