开发者

creating instance-variables at runtime?

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 g开发者_Python百科ave 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜