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.

Sunday, May 24, 2009

First iPhone App

I finished the first pass at a working iPhone app. It's a port of the SpiderMonkey Javascript engine from Mozilla. I've put together a simple UI with an editor and output text areas. Currently it only has an alert() function and a print() function for displaying results in the output text view. It does have all of the default functions and objects for JavaScript 1.7.




Source available here. I am looking to host the project somewhere, but I haven't decided on a Mercurial hosting solution that's free and allows me to upload an existing repository.

Now, I can't actually submit this to the App Store (it uses a separate language interpreter). I did it as an exercise in porting an existing application as a first step for porting another application which uses SpiderMonkey as its scripting engine. That one has a lot more graphical and file issues, so it'll be a bit more of a challenge.