This is NSBundle.rtf in view mode; [Download] [Up]
paperh18648 margl-907 margr0 margt0 margb0 fi0 ri0 ql sb0 f1 fs24 Copyright f3 'e3f1 1994 by NeXT Computer, Inc. All Rights Reserved. s8 li100 fi0 ri1007 ql f0 b fs36 fs100 fs36 NSBundle pard s18 li2872 fi-2771 ri1007 ql tx2872 f1 b0 fs28 fs48 fs28 f0 b fs24 Inherits From:tab b0 fs28 f1 NSObject fs20 fs28 s11 f0 b fs24 Conforms To:tab b0 fs28 f1 NSObject (NSObject) fs20 fs28 s12 f0 b fs24 Declared In:tab b0 fs28 f1 Foundation/NSBundle.h fs20 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs28 fs20 fs28 Class Description fs14 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 A i bundlei0 is a mechanism for grouping application i resourcesi0 into convenient chunks. A typical (but by no means the only) application of a bundle is to group executable code together with the resources used by that executable code. A major use of bundles is to handle localization issues, as described below in 'aaLocalized Resources'ba. fs16 fs28 An NSBundle is an object that corresponds to a directory (or folder in the terminology of some operating systems) where application resources are stored. The directory, in essence, 'aabundles'ba a set of resources used by an application, and the NSBundle object makes those resources available to the application. NSBundle is able to find requested resources in the directory and, in some cases, dynamically load executable code. The term 'aabundle'ba is used both for the object and for the directory it represents. fs16 fs28 Bundled resources might include such things as: fs16 fs28 pard s4 li1231 fi-376 ri1007 ql tx1231 tx2872 tx3250 'b7tab Images'd0TIFF or EPS (for instance) images used by an application'27s user interface components fs16 fs28 'b7tab Sounds fs16 fs28 'b7tab Localized character strings fs16 fs28 'b7tab Executable code fs16 fs28 'b7tab User Interface resources'd0files describing the layout of user interface objects and their relationships with other objects fs16 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 Each resource within a bundle usually resides in a separate file. fs16 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs24 fs28 Localized Resources fs14 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 If an application is to be used in more than one part of the world, its resources may need to be customized, or 'aalocalized'ba, for language, country, or cultural region. An application may need, for example, to have separate Japanese, English, French, Hindi, and Swedish versions of the character strings that label menu commands. fs16 fs28 Resource files specific to a particular language are grouped together in a subdirectory of the bundle directory. The subdirectory has the name of the language (in English) followed by a 'aa.lproj'ba extension (for 'aalanguage project'ba). The application mentioned above, for example, would have b Japanese.lprojb0 , b English.lprojb0 , b French.lprojb0 , b Hindi.lprojb0 , and b Swedish.lprojb0 subdirectories. fs16 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 Each 'aa.lproj'ba subdirectory in a bundle has the same set of files; all versions of a resource file must have the same name. fs16 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs24 fs28 The Main Bundle fs14 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 Every application is considered to have at least one bundle'd0its i main bundlei0 'd0the directory where its executable file is located. If the application is organized into a file package marked by a 'aa.app'ba extension, the file package is the main bundle. fs16 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs24 fs28 Other Bundles fs14 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 An application can be organized into any number of other bundles in addition to the main bundle. For example, an application for managing PostScript printers may have a bundle full of PostScript code to be downloaded to printers.These other bundles usually reside inside the application file package, but they can be located anywhere in the file system. Each bundle directory is represented in the application by a separate NSBundle object. fs16 fs28 By convention, bundle directories other than the main bundle end in a 'aa.bundle'ba extension. fs16 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs24 fs28 Dynamically Loadable Classes fs14 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 Any bundle directory can contain a file with executable code. For the main bundle, that file is the application executable that's loaded into memory when the application is launched. The executable in the main bundle includes the b main()b0 function and other code necessary to start up the application. fs16 fs28 Executable files in other bundle directories hold class (and category) definitions that the Bundle object can dynamically load while the application runs. When asked, the Bundle returns class objects for the classes (and categories) stored in the file. It waits to load the file until those classes are needed. fs16 fs28 By using a number of separate bundles, you can split an application into smaller, more manageable pieces. Each piece is loaded into memory only when the code being executed requires it, so the application can start up faster than it otherwise would. And, assuming users will rarely exercise every part of an application, the application will also consume less memory as it runs. fs16 fs28 The file that contains dynamically loadable code must have the same name as the bundle directory, but without the 'aa.bundle'ba extension. fs16 fs28 Since each bundle can have only one executable file, that file should be kept free of localizable content. Anything that needs to be localized should be segregated into separate resource files and stored in 'aa.lproj'ba subdirectories. fs16 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs24 fs28 Working with Bundles fs14 fs28 pard s2 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 Generally, you instantiate a bundle object by sending one of the b bundleForClass:b0 , b bundleWithPath:b0 , or b mainBundleb0 methods to the NSBundle class object. b mainBundleb0 gives you the NSBundle object corresponding to the directory containing the application'27s executable. fs16 fs28 pard s32 li100 fi0 ri1007 ql f0 b fs24 fs28 Initializing an NSBundle fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (id)b initWithPath:b0 (NSString *)i pathi0 tab Initializes a newly allocated NSBundle object to make it the NSBundle for the i pathi0 directory. pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Getting an NSBundle fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 + (NSBundle *)b bundleForClass:b0 (Class)i aClassi0 tab Returns the NSBundle object that dynamically loaded i aClassi0 , or the main bundle object if i aClassi0 wasn'27t dynamically loaded. fi-6552 fs16 fs28 fi-6552 + (NSBundle *)b bundleWithPath:b0 (NSString *)i pathi0 tab Returns an NSBundle object that'27s initialized for the i pathi0 directory. fi-6552 fs16 fs28 fi-6552 + (NSBundle *)b mainBundleb0 tab Returns the NSBundle object that corresponds to the directory where the application executable is located. pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Getting a Bundled Class fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (Class)b classNamed:b0 (NSString *)i classNamei0 tab Returns the class object for the i classNamei0 class, or b nilb0 if i classNamei0 isn'27t one of the classes associated with the receiver. fi-6552 fs16 fs28 fi-6552 {f3 -} (Class)b principalClassb0 tab Returns the class object for the i firsti0 class that'27s dynamically loaded by the NSBundle, or b nilb0 if the NSBundle can'27t dynamically load any classes. pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Finding a Resource fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 + (NSString *)b pathForResource:b0 (NSString *)i namei0 tab Returns the path for the resource identified by i namei0 , s14 li7030 fi-6553 fi-5796 b ofType:b0 (NSString *)i exti0 tab tab having the specified filename i exti0 , b inDirectory:b0 (NSString *)i bundlePathi0 tab tab residing in i bundlePath, i0 b withVersion:b0 (int)i versioni0 tab tab and having version number i versioni0 . s13 li7029 fi-5794 fi-6552 fs16 fs28 fi-6552 {f3 -} (NSString *)b pathForResource:b0 (NSString *)i namei0 tab Returns the path for the resource identified by i name s14 li7030 fi-6553 fi-5796 i0 b ofType:b0 (NSString *)i exti0 tab tab having the specified filename extension i exti0 . pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Getting the Bundle Directory fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (NSString *)b bundlePathb0 tab Returns a string containing the full pathname of the receiver'27s bundle directory. pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Stripping Symbols fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 + (void)b stripAfterLoading:b0 (BOOL)i flagi0 tab Sets whether symbols are stripped when modules are loaded. The default is YES. You would usually set i flagi0 to NO for debugging purposes. pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Managing Localized Resources fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (NSString *)b localizedStringForKey:b0 (NSString *)i keyi0 tab s14 li7030 fi-6553 fi-5796 b value:b0 (NSString *)i valuei0 tab Returns a localized version of the string designated by b table:b0 (NSString *)i tableNametab tab keyi0 .i tableName i0 specifies the string table to search; if tab tab i tableNamei0 is NULL, the file b Localizable.stringsb0 isi i0 used.i valuei0 specifies the value to return if the key or table can'27t be found (or if i keyi0 is NULL). pard s32 li100 fi0 ri1007 ql f0 b fs48 fs28 Setting the Version fs14 fs28 pard s13 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (unsigned)b bundleVersionb0 tab Returns the version last set by the b setBundleVersion:b0 method, or 0 if no version has been set. fi-6552 fs16 fs28 fi-6552 {f3 -} (void)b setBundleVersion:b0 (unsigned)i versioni0 tab Sets the version that the NSBundle will use when searching 'aa.lproj'ba subdirectories for resource files. }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.