1

hey i've got a little confusion here..

I'm using the EyeTunes Framework for a little learning project. It's an iTunes Controller.

The framework gave me an array of playlists currently existing in iTunes. As some playlists contain thousands of tracks, i plan to create arrays of the track-objects of each playlist in the "applicationDidFinishLaunching" method. (and retain those arrays)
That way when the bindings system should display the tracks list of a playlist, it does not have to load that whole list at the moment. So well so far..

Now, to create those track-arrays for each playlist i wanted to do:
(allPlaylists is an array containing all iTunes Playlists [ ETPlaylist* ];
An ETPlaylist returns an array of Tracks with it's "tracks method")

for (ETPlaylist *aPlaylist in allPlaylists){

    arrayContainingTracks = [aPlaylist tracks]

}

so

  1. How do i set a different name for "arrayContainingTracks" in each enumeration?
    And how to do that in the header file, in which all instance Vars have to be declared?

  2. and BTW: Up to which level of relationships does an array load it's contents to memory when allocated?

1 Answer 1

2

I'm not sure I entirely understand the question (why on earth would you like to change the variable name?). But the following code will insert every tracks of every playlists in arrayContainingTracks (assuming it's an instance of NSMutableArray):

for (ETPlaylist *aPlaylist in allPlaylists)
{
    [arrayContainingTracks addObjectsFromArray:[aPlaylist tracks]];
}

Note that all the tracks will be flattened in the array. If you want to pre-load every track but also keep the playlist's name, store them in an NSMutableDictionary instead:

for (ETPlaylist *aPlaylist in allPlaylists)
{
    [playlistsByName setObject:[aPlaylist tracks] forKey:[aPlaylist name]];
}

Here, I'm assuming that the ETPlaylist class has a name method.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! What i meant was not changing just the name. I thought of: In the first enum.: arrayContainingFirstPlaylistTracks = [FirstPlaylist tracks] >> In the second enum.: arrayContainingSecondPlaylistTracks = [SecondPlaylist tracks] and so on.. I know this is maybe a little weird ;)
So in your first code snippet, the array would contain all tracks without any information to which playlist they belong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.