fedor@boulder.colorado.edu
)mirko.viviani@rccr.cremona.it
)nicola@brainstorm.co.uk
)Date: 2006-08-25 08:15:45 -0600 (Fri, 25 Aug 2006)
Copyright: (C) 1995, 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSBundle.h
NSBundle provides methods for locating and handling application (and tool) resources at runtime. Resources includes any time of file that the application might need, such as images, nib (gorm or gmodel) files, localization files, and any other type of file that an application might need to use to function. Resources also include executable code, which can be dynamically linked into the application at runtime. These files and executable code are commonly put together into a directory called a bundle.
NSBundle knows how these bundles are organized and can search for files inside a bundle. NSBundle also handles locating the executable code, linking this in and initializing any classes that are located in the code. NSBundle also handles Frameworks, which are basically a bundle that contains a library archive. The organization of a framework is a little difference, but in most respects there is no difference between a bundle and a framework.
There is one special bundle, called the mainBundle, which is basically the application itself. The mainBundle is always loaded (of course), but you can still perform other operations on the mainBundle, such as searching for files, just as with any other bundle.
Return the bundle to which aClass belongs. If aClass was loaded from a bundle, return the bundle; if it belongs to a framework (either a framework linked into the application, or loaded dynamically), return the framework; if it belongs to a library, return the bundle for that library; in all other cases, return the main bundle.
Please note that GNUstep supports plain shared libraries, while the openstep standard, and other openstep-like systems, do not; the behaviour when aClass belongs to a plain shared library is to return a bundle for that library, but might be changed. :-)
Returns the bundle whose code contains the specified class.
NB: We will not find a class if the bundle has not been loaded yet!
nil
. If you want the main bundle of an application or a tool, it's better if you use +mainBundle
.
Return the bundle containing the resources for the executable. If the executable is an application, this is the main application bundle (the xxx.app directory); if the executable is a tool, this is a bundle 'naturally' associated with the tool: if the tool executable is xxx/Tools/ix86/linux-gnu/gnu-gnu-gnu/Control then the tool's main bundle directory is xxx/Tools/Resources/Control.
NB: traditionally tools didn't have a main bundle -- this is a recent GNUstep extension, but it's quite nice and it's here to stay.
The main bundle is where the application should put all of its resources, such as support files (images, html, rtf, txt,...), localization tables,.gorm (.nib) files, etc. gnustep-make (/ProjectCenter) allows you to easily specify the resource files to put in the main bundle when you create an application or a tool.
For an application, returns the main bundle of the application.
For a tool, returns the main bundle associated with the tool.
For an application, the structure is as follows -
The executable is Gomoku.app/ix86/linux-gnu/gnu-gnu-gnu/Gomoku and the main bundle directory is Gomoku.app/.
For a tool, the structure is as follows -
The executable is xxx/Tools/ix86/linux-gnu/gnu-gnu-gnu/Control and the main bundle directory is xxx/Tools/Resources/Control.
(when the tool has not yet been installed, it's similar - xxx/shared_obj/ix86/linux-gnu/gnu-gnu-gnu/Control and the main bundle directory is xxx/Resources/Control).
(For a flattened structure, the structure is the same without the ix86/linux-gnu/gnu-gnu-gnu directories).
Returns an array of paths for all resources with the specified extension and residing in the bundlePath directory. bundlePath can be any type of directory structure, but typically it is used to search for resources in a application or framework. For example, one could search for tiff files in the MyApp.app application using [NSBundle pathsForResourcesOfType: @"tiff" inDirectory: @"MyApp.app"]. It will search in any Resources subdirectory inside bundlePath as well as the main directory for resource files. If extension is nil
or empty, all resources are returned.
nil
or can't be accessed, initWithPath: deallocates the receiver and returns nil
. nil
, and a bundle with the same identifier already exists, the existing bundle is returned in place of the receiver (and the receiver is deallocated).
YES
if the receiver's code is loaded, otherwise, returns NO
.
Returns the value for the key found in the strings file tableName, or Localizable.strings if tableName is nil
.
If the user default NSShowNonLocalizedStrings
is set, the value of the key will be returned as an uppercase string rather than any localized equivalent found. This can be useful during development to check where a given string in the UI is "coming from".
Returns an absolute path for a resource name with the extension ext in the specified bundlePath. Directories in the bundle are searched in the following order:
root path/Resources/subPath root path/Resources/subPath/"language.lproj" root path/subPath root path/subPath/"language.lproj"
where language.lproj can be any localized language directory inside the bundle.
If ext is nil
or empty, then the first file with name and any extension is returned.
Returns an array of paths for all resources with the specified extension and residing in the bundlePath directory. If extension is nil
or empty, all bundle resources are returned.
- Declared in:
- Foundation/NSBundle.h
Return a bundle which accesses the first existing directory from the list GNUSTEP_USER_ROOT/Libraries/Resources/libraryName/ GNUSTEP_NETWORK_ROOT/Libraries/Resources/libraryName/ GNUSTEP_LOCAL_ROOT/Libraries/Resources/libraryName/ GNUSTEP_SYSTEM_ROOT/Libraries/Resources/libraryName/
Where libraryName is the name of a library without the lib prefix or any extensions.
This method exists to provide resource bundles for libraries and hos no particular relationship to the library code itsself. The named library could be a dynamic library linked in to the running program, a static library (whose code may not even exist on the host machine except where it is linked in to the program), or even a library which is not linked into the program at all (eg. where you want to share resources provided for a library you do not actually use).
The bundle for the library gnustep-base is a special case... for this bundle the -principalClass method returns NSObject and the -executablePath method returns the path to the gnustep-base dynamic library (if it can be found). As a general rule, library bundles are not guaranteed to return values for these methods as the library may not exist on disk.