In an app I'm working on, I'm creating custom/XML files from the users iPod (Artists, Albums, Genres, Songs, Playlists).
I'm wanting to do this on start up, so the user only has to wait once, rather than waiting each time these files are needed.
At the moment, I'm just using brute force and a "for" loop to get what I want:
Code:
NSArray * songs = [[NSArray alloc] initWithArray:[[MPMediaQuery songsQuery] collections]];
NSMutableString * fullData = [[NSMutableString alloc] init];
for (MPMediaItemCollection * item in songs){
//Add to a NSMutableString with formatting I want
}
[songs release];
[fullData writeToFile:...];
[fullData release];
The above is run in a background thread, so that the UI doesn't hang.
On the device I'm testing with, I have just over 1000 songs, and this takes about 40 seconds to do on a iPhone 3G.
I've then got to write similar files for Artists, Albums, etc.
So in total it could take a few minutes.
I've tried running them all at the same time in different threads, and running them one after the other. There doesn't seem to be a massive difference in times.
Basically I'm wondering if there is a way I'm unaware of that would allow me to decrease the loading time, or am I already using the 'best' way?
Thanks,
Tom