PDA

View Full Version : How does .app know where it is installed?


aubreyapple
02-19-2003, 10:15 AM
new to Cocoa. Two related questions:

1) I have data files I want in the package. Where is the standard place to put those files? I am guessing it is in Contents/Resources/{myfolder}.

2) After putting them there, how does one access those files in a location independent way. In other words, how do I know where the application is installed by the end user? I tried the C function getwd, but it returns '/' when the app is launched in the normal way.

If there is a document which addresses these issues, please point me to it as well. I really did try to find this on Apple's developer site and elsewhere.

Thanks

blb
02-19-2003, 02:30 PM
Originally posted by aubreyapple
new to Cocoa. Two related questions:

1) I have data files I want in the package. Where is the standard place to put those files? I am guessing it is in Contents/Resources/{myfolder}.

If you're using Project Builder, putting files in the Resources section of the project will make them appear in Contents/Resources; you can also use folders to group thing together, with the same effect.


2) After putting them there, how does one access those files in a location independent way. In other words, how do I know where the application is installed by the end user? I tried the C function getwd, but it returns '/' when the app is launched in the normal way.

The way to do this in Cocoa is using NSBundle:

[ [ NSBundle mainBundle ] resourcePath ]

gives the location of the Contents/Resources path, wherever it may be. NSBundle also has other methods to get paths for specific files; see the NSBundle docs (http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSBundle.html#//apple_ref/occ/cl/NSBundle)


If there is a document which addresses these issues, please point me to it as well. I really did try to find this on Apple's developer site and elsewhere.

Thanks
Some of it is just a matter of knowing what classes are available, and for what purpose. Going through the CurrencyConverter tutorial should help with some, reading the description of classes should help some, and of course there are several Cocoa books (http://www.cocoadev.com/index.pl?CocoaBooks). You might also read through the archives or subscribe to the mailing lists for Cocoa, one at Apple (http://www.lists.apple.com/mailman/listinfo/cocoa-dev) and one at OmniGroup (http://www.omnigroup.com/developer/mailinglists/macosx-dev/).

aubreyapple
02-19-2003, 04:08 PM
That is exactly what I wanted to know, and it works perfectly.

Thanks,