Wednesday, May 27, 2009

File Madness

One thing that has already driving me nuts about the iPhone OS is the file system interaction. It's not necessarily something that I'll have to deal with very frequently, but the way standard directories are defined is a bit of a hodge-podge:

Getting your Application bundle directory (where all of your resources are going to be written):
NSString *resourceDir = [[NSBundle mainBundle] resourcePath];

Getting the Application's Home directory, where its documents, cache, and temporary directories are (as well as the above mentioned bundle directory):
NSString *homeDir = NSHomeDirectory();

But to get any of these other directories it get's uglier:

NSArray *paths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

The least they could have done is given us a simple function to get that document directory, something like NSGetDocuemntDir(), for example.

Now, all this is in the documentation, but the bundle directory (where all your project resources go) are not considered files, so therefore, are only mentioned in passing in the File section of the documentation. I have been less then impressed by the developer documentation from apple. It's complete, but I just don't find the organization to be all that intuitive.

0 comments: