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: