Re: Can't Load Resources
Re: Can't Load Resources
- Subject: Re: Can't Load Resources
- From: Chris Espinosa <email@hidden>
- Date: Tue, 8 Jun 2004 10:32:07 -0700
On Jun 8, 2004, at 10:06 AM, Ricky Sharp wrote:
On Tuesday, June 08, 2004, at 10:15AM, Ken Brooks <email@hidden>
wrote:
Under a target I find two headings: Bundle Resources, and Resource
Manager Resources.
In one project the program couldn't load its resources until I moved
the resource file into Resource Manager Resources. In a very similar
project I did the same and the program STILL can't load its
resources. (I have a MENU 10 that I use as my test item; GetResource
fails to load it.)
What is this distinction all about? Can someone point me to a help
page that really explains the whole resource deal in this new world?
Bundle Resources are basically any file that you want to place in the
Resource folder in your bundle (e.g. image files).
Resource Manager Resources are special "items" contained in a single
file that are to be used with the Resource Manager APIs (e.g.
GetResource). In the old days, you would put many user-interface
items in the resource-fork of your application binary. You'd also put
icons, document-binding info, strings, etc in there too.
By using nibs, you can move away from using Res Mgr resources for your
UI and any STR#, STR, etc. resources can be replaced by .strings
files.
I still use Res Mgr resources, but now only for my proprietary data
types.
Xcode will take any .r (raw text-file describing resources), .rsrc
(resource-fork-based files), and merge them into a single
data-fork-based .rsrc file that is placed inside the Resource folder
in your bundle. The root name of the .rsrc file will match the root
name of your application. Upon startup, the runtime system loads this
data-fork-based file for you and you can issue the Resource Manager
API calls as if those resources lived in the resource-fork on the app
binary.
Icon data (.icns files) and image data (.pct, .jpg, etc.) can live as
resource-based data, but often are more convenient as being separate
files. For example, my application allows users to download new
themes. Each theme file is placed inside the bundle's Resource folder
and also has a corresponding thumnail (.pct) file. My app makes use
of the "Get Resource" APIs in CFBundle.h. The application icon and
any document icons are stored as .icns files in the Resource folder.
Rick's description is excellent, and I'd just add this clarification.
If you add .r (or .rsrc) files to the ResourceManager Resources build
phase of a target that creates a bundled product, the resources in
those .r files will be available to Carbon Resource Manager calls when
the bundle is open (by the mechanism Rick describes above.)
If you include resource files that don't end in .rsrc but are
resource-fork or data-fork resources, those files will simply be copied
into the Resources folder of your bundle, and you'll have to open them
yourself before you can successfully call the Resource Manager to load
resources from them.
In Mac OS X it's preferable to put your resources in the data fork of
the resource file, rather than the resource fork. Your bundle can then
be put on non-Mac file systems and servers, and be copied by UNIX and
Windows utilities, without losing its resources.
To move a file's resource fork to its data fork, you can do this:
cp foo.rsrc/..NamedFork/rsrc bar.rsrc
rm foo.rsrc
mv bar.rsrc foo.rsrc
Chris
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.