views:

783

answers:

3

The problem is that my app saves hundreds of megabytes into the users document directory on their iPhone. During testing, the iPhone simulator takes a long time to launch the app on each build as it is copying all of this data to a new documents directory each time I rebuild. Is there any solution to this that will just leave the directory in the same place each time or speed up launch in some way? For example, the director with HEX values change each rebuild/relaunch on the iPhone Simulator and it can be quite time consuming:

./Library/Application Support/iPhone Simulator/User/Applications/B32A0BA1-5843-4FDE-B5FB-4E40460BD8CC/Documents/

Thanks,

Matt

A: 

To shorten your build time, the easiest thing is probably to create a new XCode target that includes a reasonable subset of the data. Assuming that these data files are "Resource" files in the XCode project, you can duplicate your app target, rename it "app lite" or some-such , then edit the "Copy Resources" build phase to not include all of the files (or a single smaller file, or whatever).

Mark Bessey
Sorry if I wasn't more clear, but these files are not "Resource" files in the XCode project, but rather files that are saved to the documents directory by my App while running ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]). Thanks for the reply.
Matt
A: 

XCode doesn't make a new directory each time you build and run, it just renames the old one.

I have data that I store in the documents directory and its there every launch unless I explicitly delete it before running my app.

I'd be curious as to where the time is taken when launching the simulator. Can you debug through the app? (is it your code thats taking the time?)

chris.

PyjamaSam
Hi PyjamaSam. You are probably correct that it renames the directory (I just watched what happened while launching the app), but the Simulator seems to be doing something with the documents during the launch phase. For instance, my app has a 3MB sqlite file and 250 MB of photos in the Documents directory. On launch, my code does nothing with these photo files, but quite a bit with the SQL file. However, if I remove the photo files from the Documents dir, it launches instantly. Putting them back in causes a 10 second delay before the app even begins to launch (just the spinning color wheel)
Matt
+6  A: 

The simulator (unlike the device itself) doesn't have to keep to the sandboxed locations.

So when saving files from the simulator, you could try:

#if TARGET_IPHONE_SIMULATOR

// save your files to a fixed location on your hard-disk
// (like /Users/yourusername/MyIPhoneAppDebugStorage)

#else

// Save files normally
// (to [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
//     NSUserDomainMask, YES) objectAtIndex:0])

#endif

That way, your large files are always at a fixed place on your harddisk when running from the simulator.

Matt Gallagher
Thanks -- this works perfectly! My Simulator was taking almost 10 minutes to load the app when I had 1.5 GB of data in the NSDocumentDirectory, but is now loading almost instantly with the above fix.
Matt