views:

76

answers:

2

Hi,

While playing with RubyCocoa, I keep progressing with my idea for my application. Because my application will be going to use configuration files, I would like to know how I discover the relative path to store these inside my application structure (or if a better idea emerges, please elaborate also the "why").

Also good for me to know is to discover environment variables, such as operating system version, the amount of memory that is available and such. Hyperlinks would be awesome too.

Please notice I use RubyCocoa and thank you for your feedback, comments and answers!

+2  A: 

To access inside the application bundle, you use NSBundle. See NSBundle reference. In Obj-C, you use +[NSBundle mainBundle] to get the main bundle of the app. Then you use -[NSBundle pathForResource:ofType:] to get the file. I don't know RubyCocoa syntax, but I assume you know how to translate to it :)

If by the configuration file you mean a user-configurable things, remember you can't write inside the app bundle at runtime. Instead one uses NSUserDefaults. See User Defaults Guide.

Yuji
Thanks a bunch, I am going to look inside these two.
Shyam
+1  A: 

Here's some Cocoa code I use to write all the environment variables to the console. Again, I don't use RubyCocoa, so you'll have to translate:

NSProcessInfo *myProcessInfo = [NSProcessInfo processInfo]; 
    NSDictionary *env = [myProcessInfo environment];
    for (id key in env)
    {
        NSLog (@"key: %@, value: %@", key, [env objectForKey: key]);
    }
Sweet :) Thanks a bunch!
Shyam