Important: The information in this document is obsolete and should not be used for new development.
In addition to source code, most projects include resources such as images, sounds, and nib resource files. Many project templates provide default resource files when you create a new project; these resource files are typically organized in the Resources source group. In addition, when you add resource files to a target, Xcode automatically adds them to the correct step of the build process, so that they will be added to your software.
Most Mac OS X software, including applications, plug-ins, and frameworks, is packaged in the form of a bundle. Xcode provides mechanisms both to help you localize resource files that need it, and, when you build your product, to copy localized resources into localized directories in your software bundle. At runtime, your source code can use various APIs provided by Mac OS X to obtain localized information from the bundle.
The following sections provide an overview of how to work with resources, support localization, and provide needed information to the Mac OS X system. To learn more about working with localized files in Xcode, see “Customizing for Different Regions.”
Information Property List Files
Strings Files
Nib Files
Resource Manager Files
Any Mac OS X software that is packaged in the form of a bundle requires an information property list file named Info.plist. This file, which is critical to configuring your software, contains key-value pairs that specify various information used at runtime, such as the version number. Information in the property list is used by Mac OS X (for example, when launching applications) and is also available to the product that contains the property list.
When you create a new project for a bundled product, Xcode automatically creates an Info.plist file for the project. When you build the product, Xcode copies the property list file into the product’s bundle. The information property list is associated with a target, and you can open an Info window on the target to modify property list values. You can also double-click a property list file in the project window to edit it as an XML text file.
Any text strings in your project that may be displayed to users should be localized. To do this, you place them in strings files, providing one localized variant for each language you support. A strings file, which has the extension strings, stores a series of keys and values, where the values are the strings and the keys uniquely identify the strings. Xcode supports localization with strings files by providing options to make a file localizable and to add files for local variants.
When you build your product, Xcode copies each localized strings file into the appropriate localized directory within the Resources directory of the product bundle. For example, if you localize for French, the French version of a strings file is copied to the French.lproj directory in the bundle. Mac OS X provides various APIs you can use in your source code to obtain localized information from a bundle, such as the correct text string to display for the user’s current locale. For more information, see Internationalization Programming Topics.
The InfoPlist.strings file is an example of a strings file. It is used to provide localized values for any properties in the Info.plist file that may be displayed to users. When you create a new project for a bundled product, Xcode automatically creates this file in the Resources group. By default, it provides just an English variant, but you can add localized strings files for other languages you support.
A nib file, which has the extension nib, is a resource file that stores user interface information for a product. You create nib files with Interface Builder, which provides a powerful mechanism for graphically laying out the user interface for your software. When you add a nib file to a target, Xcode adds it to the correct stage of the build process, which causes it to be copied into the product’s bundle when you build the product. Your code then has access, at runtime, to user interface items in the nib file.
Important: Because nib files are bundles, which means they are really a directory structure, not a single file, you must use special mechanisms to check them in and out with some SCM systems.
In previous versions of the Mac OS, applications traditionally used Resource Manager .r (text) and .rsrc (compiled) resource files. While nib files are now the preferred mechanism for defining user interface items, Xcode has built-in support for Resource Manager resources as well.
When you add a Resource Manager resource file to a target, Xcode recognizes it by its extension. When it builds the target, Xcode automatically compiles .r files with the Rez tool. Xcode then copies the resulting .rsrc file into the Resources folder of the product bundle. If you localize any .r files, a .rsrc file is copied into the appropriate localized directory as well.
For related information about these types of resources, see “Working With Resources” in Porting CodeWarrior Projects to Xcode.
Last updated: 2006-11-07