0
votes

I'm using cocoalibspotify for a Spotify iOS app.

At one point in my app, I'm creating a new playlist and add a number of tracks to the playlist. When doing so, I'm getting a crash since the created playlist instance seem to have been deallocated.

This is what the code looks like:

[[[SPSession sharedSession] userPlaylists] 
 createPlaylistWithName:playlistName 
 callback:^(SPPlaylist *createdPlaylist) {
     if (createdPlaylist) {
          [SPAsyncLoading waitUntilLoaded:createdPlaylist 
                                     then:^(NSArray *playlists) {
                                        // Load all tracks using the URI's and add them to the playlist
                                        SPPlaylist *playlist = [playlists objectAtIndex:0];
                                        for (NSString *trackUri in trackUris) {
                                            [[SPSession sharedSession] 
                                                trackForURL:[NSURL URLWithString:trackUri] 
                                                callback:^(SPTrack *track) {
                                                if (track != nil) {
                                                    [SPAsyncLoading 
                                                     waitUntilLoaded:track 
                                                     then:^(NSArray *tracks) {
                                                         [playlist addItems:tracks atIndex:0 callback:NULL];
                                                     }];
                                                }
                                            }];
                                        }
                                    }];
    }}];

This is the log message:

*** -[SPPlaylistCallbackProxy playlist]: message sent to deallocated instance 0x100e0120

I've tried retaining the playlist in my class, but I'm still getting the same problem. Am I missing something obvious here?

Bonus question: After having created a playlist or loaded a track (i.e. using -trackForURL:callback), do I have to use SPAsyncLoading, or is the object always already loaded?

(Note: I'm using ARC in my project.)

EDIT: I ran Zombies in instruments to see what was going on and got the following result when it crashed: Retain/release history of the instance

1

1 Answers

1
votes

If you have an object (SPTrack, etc), you can add it to a playlist without waiting for it to load since loading only deals with metadata. You might want to wait for the playlist to load so you know the indexes you're using are correct (although, in this case 0 will always be valid).

Looking into the meat of your question now. It's most likely a bug in CocoaLibSpotify - your code looks fine.