0
votes

I´m using cocoalibspotify(great stuff) for streaming Spotify music in my project.

After choosing a playlist this code runs:

 [[SPSession sharedSession] playlistForURL:myPlaylistUrl callback:^(SPPlaylist *playlist) {
    if(playlist != nil){

        _chosenPlaylist = playlist;
    }
}];

I later use _chosenPlaylist to create an array of all tracks. This works just fine for the first playlist I choose. However, when I choose another playlist (or the same one again) the block variable playlist is nil, which causes a crash.

Note: Before choosing the second playlist I dismiss the view controller so it should act the same way as it does the first time.

Any ideas on why playlist returns as nil the second time I run this code?

Edit: I´m using ARC. The declaration for _chosenPlaylist looks like this SPPlaylist *_chosenPlaylist;

The crash occurs because of this line: [playlists addObject:_chosenPlaylist];, which makes sense since _chosenPlaylist is nil in this situation.

1
A bit more info please: Are you using ARC? How is _chosenPlaylist declared? The code you posted checks playlist for nil, so where is the crash actually occurring?iKenndac
Hi @iKenndac, I´ve updated my post with some more information. Thank you.marsrover

1 Answers

0
votes

Basically, the only way that playlistForURL:callback: can return a nil playlist is if you're giving it an invalid URL. Double check your input (the value of myPlaylistUrl) - only URLs of the from spotify:user:xxx:playlist:yyy are accepted.