Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
 
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 ;) –  bijan Nov 5 '10 at 2:12
 
So in your first code snippet, the array would contain all tracks without any information to which playlist they belong? –  bijan Nov 5 '10 at 2:18
 
@bijan Yes, the first code snippet only saves the tracks. –  Martin Cote Nov 8 '10 at 3:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.