iOS Developer Library

Developer

Foundation Framework Reference NSBundle Class Reference

Options
Deployment Target:

On This Page
Language:

NSBundle

An NSBundle object represents a location in the file system that groups code and resources that can be used in a program. NSBundle objects locate program resources, dynamically load and unload executable code, and assist in localization. You build a bundle in Xcode using one of these project types: Application, Framework, plug-ins.

Although bundle structures vary depending on the target platform and the type of bundle you are building, the NSBundle class hides this underlying structure in most (but not all) cases. Many of the methods you use to load resources from a bundle automatically locate the appropriate starting directory and look for resources in known places. For information about application bundle structures (for OS X and iOS), see Bundle Programming Guide. For information about the structure of framework bundles, see Framework Programming Guide. For information about the structure of OS X plug-ins, see Code Loading Programming Topics.

For additional information about how to load nib files and images in a Mac app, see NSBundle AppKit Additions Reference. For information about how to load nib files in an iOS application, see NSBundle UIKit Additions Reference.

Unlike some other Foundation classes with corresponding Core Foundation names (such as NSString and CFString), NSBundle objects cannot be cast (“toll-free bridged”) to CFBundle references. If you need functionality provided in CFBundle, you can still create a CFBundle and use the CFBundle Reference API. See Interchangeable Data Types for more information on toll-free bridging.

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later.
  • Returns an NSBundle object that corresponds to the specified file URL.

    Declaration

    Objective-C

    + (instancetype)bundleWithURL:(NSURL *)url

    Parameters

    url

    The URL to a directory. This must be a URL for a directory; if it contains any symbolic links, they must be resolvable.

    Return Value

    The NSBundle object that corresponds to url, or nil if url does not identify an accessible bundle directory.

    Discussion

    This method allocates and initializes the returned object if there is no existing NSBundle associated with url, in which case it returns the existing object.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 4.0 and later.

  • Returns an NSBundle object that corresponds to the specified directory.

    Declaration

    Objective-C

    + (instancetype)bundleWithPath:(NSString *)fullPath

    Parameters

    fullPath

    The path to a directory. This must be a full pathname for a directory; if it contains any symbolic links, they must be resolvable.

    Return Value

    The NSBundle object that corresponds to fullPath, or nil if fullPath does not identify an accessible bundle directory.

    Discussion

    This method allocates and initializes the returned object if there is no existing NSBundle associated with fullPath, in which case it returns the existing object.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 2.0 and later.

  • Returns an NSBundle object initialized to correspond to the specified file URL.

    Declaration

    Swift

    convenience init?(URL url: NSURL)

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url

    Parameters

    url

    The file URL to a directory. This must be a full URL for a directory; if it contains any symbolic links, they must be resolvable.

    Return Value

    An NSBundle object initialized to correspond to url. This method initializes and returns a new instance only if there is no existing bundle associated with url, otherwise it deallocates self and returns the existing object. If url doesn’t exist or the user doesn’t have access to it, returns nil.

    Discussion

    It’s not necessary to allocate and initialize an instance for the main bundle; use the mainBundle class method to get this instance. You can also use the bundleWithURL: class method to obtain a bundle identified by its file URL.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • init(path:) - initWithPath: Designated Initializer

    Returns an NSBundle object initialized to correspond to the specified directory.

    Declaration

    Swift

    init?(path fullPath: String)

    Objective-C

    - (instancetype)initWithPath:(NSString *)fullPath

    Parameters

    fullPath

    The path to a directory. This must be a full pathname for a directory; if it contains any symbolic links, they must be resolvable.

    Return Value

    An NSBundle object initialized to correspond to fullPath. This method initializes and returns a new instance only if there is no existing bundle associated with fullPath, otherwise it deallocates self and returns the existing object. If fullPath doesn’t exist or the user doesn’t have access to it, returns nil.

    Discussion

    It’s not necessary to allocate and initialize an instance for the main bundle; use the mainBundle class method to get this instance. You can also use the bundleWithPath: class method to obtain a bundle identified by its directory path.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the NSBundle object with which the specified class is associated.

    Declaration

    Swift

    init(forClass aClass: AnyClass) -> NSBundle

    Objective-C

    + (NSBundle *)bundleForClass:(Class)aClass

    Parameters

    aClass

    A class.

    Return Value

    The NSBundle object that dynamically loaded aClass (a loadable bundle), the NSBundle object for the framework in which aClass is defined, or the main bundle object if aClass was not dynamically loaded or is not defined in a framework.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the previously created NSBundle instance that has the specified bundle identifier.

    Declaration

    Swift

    init?(identifier identifier: String) -> NSBundle

    Objective-C

    + (NSBundle *)bundleWithIdentifier:(NSString *)identifier

    Parameters

    identifier

    The identifier for an existing NSBundle instance.

    Return Value

    The previously created NSBundle instance that has the bundle identifier identifier. Returns nil if the requested bundle is not found.

    Discussion

    This method is typically used by frameworks and plug-ins to locate their own bundle at runtime. This method may be somewhat more efficient than trying to locate the bundle using the bundleForClass: method. However, if the initial lookup of an already loaded and cached bundle with the specified identifier fails, this method uses potentially time-consuming heuristics to attempt to locate the bundle.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the NSBundle object that corresponds to the directory where the current application executable is located.

    Declaration

    Swift

    class func mainBundle() -> NSBundle

    Objective-C

    + (NSBundle *)mainBundle

    Return Value

    The NSBundle object that corresponds to the directory where the application executable is located, or nil if a bundle object could not be created.

    Discussion

    This method allocates and initializes a bundle object if one doesn’t already exist. The new object corresponds to the directory where the application executable is located. Be sure to check the return value to make sure you have a valid bundle. This method may return a valid bundle object even for unbundled applications.

    In general, the main bundle corresponds to an application file package or application wrapper: a directory that bears the name of the application and is marked by a “.app” extension.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of all the application’s non-framework bundles.

    Declaration

    Swift

    class func allBundles() -> [AnyObject]

    Objective-C

    + (NSArray *)allBundles

    Return Value

    An array of all the application’s non-framework bundles.

    Discussion

    The returned array includes the main bundle and all bundles that have been dynamically created but doesn’t contain any bundles that represent frameworks.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of all of the application’s bundles that represent frameworks.

    Declaration

    Swift

    class func allFrameworks() -> [AnyObject]

    Objective-C

    + (NSArray *)allFrameworks

    Return Value

    An array of all of the application’s bundles that represent frameworks. Only frameworks with one or more Objective-C classes in them are included.

    Discussion

    The returned array includes frameworks that are linked into an application when the application is built and bundles for frameworks that have been dynamically created.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the Class object for the specified name.

    Declaration

    Swift

    func classNamed(_ className: String) -> AnyClass?

    Objective-C

    - (Class)classNamed:(NSString *)className

    Parameters

    className

    The name of a class.

    Return Value

    The Class object for className. Returns nil if className is not one of the classes associated with the receiver or if there is an error loading the executable code containing the class implementation.

    Discussion

    If the bundle’s executable code is not yet loaded, this method dynamically loads it into memory. Classes (and categories) are loaded from just one file within the bundle directory; this code file has the same name as the directory, but without the extension (“.bundle”, “.app”, “.framework”). As a side effect of code loading, the receiver posts NSBundleDidLoadNotification after all classes and categories have been loaded; see Notifications for details.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The bundle’s principal class. (read-only)

    Declaration

    Swift

    var principalClass: AnyClass? { get }

    Objective-C

    @property(readonly) Class principalClass

    Discussion

    This property is set after ensuring that the code containing the definition of the class is dynamically loaded. If the bundle encounters errors in loading or if it can’t find the executable code file in the bundle directory, this property is nil.

    The principal class typically controls all the other classes in the bundle; it should mediate between those classes and classes external to the bundle. Classes (and categories) are loaded from just one file within the bundle directory. The bundle obtains the name of the code file to load from the dictionary returned from infoDictionary, using “NSExecutable” as the key. The bundle determines its principal class in one of two ways:

    • It first looks in its own information dictionary, which extracts the information encoded in the bundle’s property list (Info.plist). The bundle obtains the principal class from the dictionary using the key NSPrincipalClass. For non-loadable bundles (applications and frameworks), if the principal class is not specified in the property list, this property is nil.

    • If the principal class is not specified in the information dictionary, the bundle identifies the first class loaded as the principal class. When several classes are linked into a dynamically loadable file, the default principal class is the first one listed on the ld command line. In the following example, Reporter would be the principal class:

    • ld -o myBundle -r Reporter.o NotePad.o QueryList.o

    The order of classes in Xcode’s project browser is the order in which they will be linked. To designate the principal class, control-drag the file containing its implementation to the top of the list.

    As a side effect of code loading, the receiver posts NSBundleDidLoadNotification after all classes and categories have been loaded; see Notifications for details.

    The following method obtains a bundle by specifying its path (bundleWithPath:), then loads the bundle with principalClass and uses the principal class object to allocate and initialize an instance of that class:

    • - (void)loadBundle:(id)sender
    • {
    • Class exampleClass;
    • id newInstance;
    • NSString *path = @"/tmp/Projects/BundleExample/BundleExample.bundle";
    • NSBundle *bundleToLoad = [NSBundle bundleWithPath:path];
    • if (exampleClass = bundleToLoad.principalClass) {
    • newInstance = [[exampleClass alloc] init];
    • [newInstance doSomething];
    • }
    • }

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the file URL for the resource file identified by the specified name and extension and residing in a given bundle directory.

    Declaration

    Swift

    func URLForResource(_ name: String, withExtension extension: String?, subdirectory subpath: String?) -> NSURL?

    Objective-C

    - (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)extension subdirectory:(NSString *)subpath

    Parameters

    name

    The name of a resource file contained in the directory specified by bundleURL.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matches name.

    subpath

    The path of a top-level bundle directory. This must be a valid path. For example, to specify the bundle directory for a Mac app, you might specify the path /Applications/MyApp.app.

    Return Value

    The file URL for the resource file or nil if the file could not be located. This method also returns nil if the bundle specified by the bundlePath parameter does not exist or is not a readable directory.

    Discussion

    For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns the full pathname for the resource file identified by the specified name and extension and residing in a given bundle directory.

    Declaration

    Swift

    class func pathForResource(_ name: String?, ofType extension: String?, inDirectory bundlePath: String) -> String?

    Objective-C

    + (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)bundlePath

    Parameters

    name

    The name of a resource file contained in the directory specified by bundlePath.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file is the first file encountered that exactly matches name.

    bundlePath

    The path of a top-level bundle directory. This must be a valid path. For example, to specify the bundle directory for a Mac app, you might specify the path /Applications/MyApp.app.

    Return Value

    The full pathname for the resource file or nil if the file could not be located. This method also returns nil if the bundle specified by the bundlePath parameter does not exist or is not a readable directory.

    Discussion

    For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the file URL for the resource identified by the specified name and file extension.

    Declaration

    Swift

    func URLForResource(_ name: String, withExtension extension: String?) -> NSURL?

    Objective-C

    - (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)extension

    Parameters

    name

    The name of the resource file.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matches name.

    Return Value

    The file URL for the resource file or nil if the file could not be located.

    Discussion

    If extension is an empty string or nil, the returned pathname is the first one encountered where the file name exactly matches name. For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns the full pathname for the resource identified by the specified name and file extension.

    Declaration

    Swift

    func pathForResource(_ name: String?, ofType extension: String?) -> String?

    Objective-C

    - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

    Parameters

    name

    The name of the resource file. If name is an empty string or nil, returns the first file encountered of the supplied type.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file is the first file encountered that exactly matches name.

    Return Value

    The full pathname for the resource file or nil if the file could not be located.

    Discussion

    The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. If a matching resource file is not found, it then looks in the top level of an available language-specific .lproj folder. (The search order for the language-specific folders corresponds to the user’s preferences.) It does not recurse through other subfolders at any of these locations. For more details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    The following code fragment gets the path to a plist within the bundle, and loads it into an NSDictionary.

    • NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
    • if (commonDictionaryPath = [thisBundle pathForResource:@"CommonDictionary" ofType:@"plist"]) {
    • theDictionary = [[NSDictionary alloc] initWithContentsOfFile:commonDictionaryPath];
    • }

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array of file URLs for all resources identified by the specified file extension and located in the specified bundle subdirectory.

    Declaration

    Swift

    func URLsForResourcesWithExtension(_ extension: String?, subdirectory subpath: String?) -> [AnyObject]?

    Objective-C

    - (NSArray *)URLsForResourcesWithExtension:(NSString *)extension subdirectory:(NSString *)subpath

    Parameters

    extension

    The file extension of the files to locate.

    subpath

    The name of the bundle subdirectory.

    Return Value

    An array of file URLs for the resource files or nil if no files could be located at subpath with extension. Returns an empty array if no matching resource files are found.

    Discussion

    If subpath is nil, this method searches the top-level non-localized resource directory and the top-level of any language-specific directories. (In OS X, the top-level non-localized resource directory is typically called Resources but in iOS, it is the main bundle directory.)

    For example, suppose you have a Mac app with a modern bundle and you specify @"Documentation" for the subpath parameter. This method would first look in the Contents/Resources/Documentation directory of the bundle, followed by the Documentation subdirectories of each language-specific .lproj directory. (The search order for the language-specific directories corresponds to the user’s preferences.) This method does not recurse through any other subdirectories at any of these locations. For more details see The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns the full pathname for the resource identified by the specified name and file extension and located in the specified bundle subdirectory.

    Declaration

    Swift

    func pathForResource(_ name: String?, ofType extension: String?, inDirectory subpath: String?) -> String?

    Objective-C

    - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)subpath

    Parameters

    name

    The name of the resource file.

    extension

    If extension is an empty string or nil, all the files in subpath and its subdirectories are returned. If an extension is provided the subdirectories are not searched.

    subpath

    The name of the bundle subdirectory. Can be nil.

    Return Value

    An array of full pathnames for the subpath or nil if no files are located.

    Discussion

    If subpath is nil, this method searches the top-level nonlocalized resource directory and the top-level of any language-specific directories. (In OS X, the top-level nonlocalized resource directory is typically called Resources but in iOS, it is the main bundle directory.) For example, suppose you have a Mac app with a modern bundle and you specify @"Documentation" for the subpath parameter. This method would first look in the Contents/Resources/Documentation directory of the bundle, followed by the Documentation subdirectories of each language-specific .lproj directory.

    Whether this method recurses through subdirectories is dependent on the extension parameter. If nil or an empty string it will recurse, otherwise, it does not. (The search order for the language-specific directories corresponds to the user’s preferences.) For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the file URL for the resource identified by the specified name and file extension, located in the specified bundle subdirectory, and limited to global resources and those associated with the specified localization.

    Declaration

    Swift

    func URLForResource(_ name: String, withExtension extension: String?, subdirectory subpath: String?, localization localizationName: String?) -> NSURL?

    Objective-C

    - (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)extension subdirectory:(NSString *)subpath localization:(NSString *)localizationName

    Parameters

    name

    The name of the resource file.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matches name.

    subpath

    The name of the bundle subdirectory to search.

    localizationName

    The language ID for the localization. This parameter should correspond to the name of one of the bundle's language-specific resource directories without the .lproj extension.

    Return Value

    The file URL for the resource file or nil if the file could not be located.

    Discussion

    This method is equivalent to URLsForResourcesWithExtension:subdirectory:, except that only nonlocalized resources and those in the language-specific .lproj directory specified by localizationName are searched.

    There should typically be little reason to use this method—see Getting the Current Language and Locale. See also preferredLocalizationsFromArray:forPreferences: for how to determine what localizations are available.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns the full pathname for the resource identified by the specified name and file extension, located in the specified bundle subdirectory, and limited to global resources and those associated with the specified localization.

    Declaration

    Swift

    func pathForResource(_ name: String?, ofType extension: String?, inDirectory subpath: String?, forLocalization localizationName: String?) -> String?

    Objective-C

    - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName

    Parameters

    name

    The name of the resource file.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file is the first file encountered that exactly matches name.

    subpath

    The name of the bundle subdirectory to search.

    localizationName

    The language ID for of the localization. This parameter should correspond to the name of one of the bundle's language-specific resource directories without the .lproj extension.

    Return Value

    The full pathname for the resource file or nil if the file could not be located.

    Discussion

    This method is equivalent to pathForResource:ofType:inDirectory:, except that only nonlocalized resources and those in the language-specific .lproj directory specified by localizationName are searched.

    There should typically be little reason to use this method—see Getting the Current Language and Locale. See also preferredLocalizationsFromArray:forPreferences: for how to determine what localizations are available.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array containing the pathnames for all bundle resources having the specified extension and residing in the bundle directory at the specified path.

    Declaration

    Swift

    class func pathsForResourcesOfType(_ extension: String?, inDirectory bundlePath: String) -> [AnyObject]

    Objective-C

    + (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)bundlePath

    Parameters

    extension

    The file extension. If extension is an empty string or nil, the extension is assumed not to exist, all the files in bundlePath are returned.

    bundlePath

    The top-level directory of a bundle. This must represent a valid path.

    Return Value

    An array containing the full pathnames for all bundle resources with the specified extension. This method returns an empty array if no matching resource files are found. It also returns an empty array if the bundle specified by the bundlePath parameter does not exist or is not a readable directory.

    Discussion

    This method provides a means for dynamically discovering multiple bundle resources of the same type. For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array containing the pathnames for all bundle resources having the specified filename extension and residing in the resource subdirectory.

    Declaration

    Swift

    func pathsForResourcesOfType(_ extension: String?, inDirectory subpath: String?) -> [AnyObject]

    Objective-C

    - (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)subpath

    Parameters

    extension

    The file extension. If extension is an empty string or nil, the extension is assumed not to exist, all the files in subpath are returned.

    subpath

    The name of the bundle subdirectory to search.

    Return Value

    An array containing the full pathnames for all bundle resources matching the specified criteria. This method returns an empty array if no matching resource files are found.

    Discussion

    This method provides a means for dynamically discovering multiple bundle resources of the same type. If extension is an empty string or nil, all bundle resources in the specified resource directory are returned.

    The argument subpath specifies the name of a specific subdirectory to search within the current bundle’s resource directory hierarchy. If subpath is nil, this method searches the top-level nonlocalized resource directory and the top-level of any language-specific directories. (In OS X, the top-level nonlocalized resource directory is typically called Resources but in iOS, it is the main bundle directory.) For example, suppose you have a Mac app with a modern bundle and you specify @"Documentation" for the subpath parameter. This method would first look in the Contents/Resources/Documentation directory of the bundle, followed by the Documentation subdirectories of each language-specific .lproj directory. (The search order for the language-specific directories corresponds to the user’s preferences.) This method does not recurse through any other subdirectories at any of these locations. For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an array containing the file URLs for all bundle resources having the specified filename extension, residing in the specified resource subdirectory, and limited to global resources and those associated with the specified localization.

    Declaration

    Swift

    func URLsForResourcesWithExtension(_ extension: String?, subdirectory subpath: String?, localization localizationName: String?) -> [AnyObject]?

    Objective-C

    - (NSArray *)URLsForResourcesWithExtension:(NSString *)extension subdirectory:(NSString *)subpath localization:(NSString *)localizationName

    Parameters

    extension

    The file extension of the files to locate.

    subpath

    The name of the bundle subdirectory to search.

    localizationName

    The language ID for the localization. This parameter should correspond to the name of one of the bundle's language-specific resource directories without the .lproj extension.

    Return Value

    An array containing the file URLs for all bundle resources matching the specified criteria. This method returns an empty array if no matching resource files are found.

    Discussion

    This method is equivalent to URLsForResourcesWithExtension:subdirectory:, except that only nonlocalized resources and those in the language-specific .lproj directory specified by localizationName are searched.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns an array containing the file for all bundle resources having the specified filename extension, residing in the specified resource subdirectory, and limited to global resources and those associated with the specified localization.

    Declaration

    Swift

    func pathsForResourcesOfType(_ extension: String?, inDirectory subpath: String?, forLocalization localizationName: String?) -> [AnyObject]

    Objective-C

    - (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName

    Parameters

    extension

    The file extension of the files to retrieve.

    subpath

    The name of the bundle subdirectory to search.

    localizationName

    The language ID for the localization. This parameter should correspond to the name of one of the bundle's language-specific resource directories without the .lproj extension.

    Return Value

    An array containing the full pathnames for all bundle resources matching the specified criteria. This method returns an empty array if no matching resource files are found.

    Discussion

    This method is equivalent to pathsForResourcesOfType:inDirectory:, except that only nonlocalized resources and those in the language-specific .lproj directory specified by localizationName are searched.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Creates and returns a file URL for the resource with the specified name and extension in the specified bundle.

    Declaration

    Swift

    class func URLForResource(_ name: String, withExtension extension: String?, subdirectory subpath: String?, inBundleWithURL bundleURL: NSURL) -> NSURL?

    Objective-C

    + (NSURL *)URLForResource:(NSString *)name withExtension:(NSString *)extension subdirectory:(NSString *)subpath inBundleWithURL:(NSURL *)bundleURL

    Parameters

    name

    The name of the resource file.

    extension

    If extension is an empty string or nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matches name.

    subpath

    The name of the bundle subdirectory to search.

    bundleURL

    The file URL of the bundle to search.

    Return Value

    The file URL for the resource file or nil if the file could not be located.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns an array containing the file URLs for all bundle resources having the specified filename extension, residing in the specified resource subdirectory, within the specified bundle.

    Declaration

    Swift

    class func URLsForResourcesWithExtension(_ extension: String?, subdirectory subpath: String?, inBundleWithURL bundleURL: NSURL) -> [AnyObject]?

    Objective-C

    + (NSArray *)URLsForResourcesWithExtension:(NSString *)extension subdirectory:(NSString *)subpath inBundleWithURL:(NSURL *)bundleURL

    Parameters

    extension

    The file extension of the files to locate.

    subpath

    The name of the bundle subdirectory to search.

    bundleURL

    The file URL of the bundle to search.

    Return Value

    An array of file URLs for the resource files matching the criteria or an empty array if no files could be located.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the bundle’s subdirectory containing resources. (read-only)

    Declaration

    Swift

    var resourcePath: String? { get }

    Objective-C

    @property(readonly, copy) NSString *resourcePath

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    bundlePath

  • The file URL for the bundle’s App Store receipt. (read-only)

    Declaration

    Swift

    @NSCopying var appStoreReceiptURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *appStoreReceiptURL

    Discussion

    For an application purchased from the App Store, use this application bundle property to locate the receipt. This property makes no guarantee about whether there is a file at the URL—only that if a receipt is present, that is its location.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 7.0 and later.

  • bundleURL bundleURL Property

    The full URL of the receiver’s bundle directory. (read-only)

    Declaration

    Swift

    @NSCopying var bundleURL: NSURL { get }

    Objective-C

    @property(readonly, copy) NSURL *bundleURL

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the receiver’s bundle directory. (read-only)

    Declaration

    Swift

    var bundlePath: String { get }

    Objective-C

    @property(readonly, copy) NSString *bundlePath

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The receiver’s bundle identifier. (read-only)

    Declaration

    Swift

    var bundleIdentifier: String? { get }

    Objective-C

    @property(readonly, copy) NSString *bundleIdentifier

    Discussion

    The bundle identifier is defined by the CFBundleIdentifier key in the bundle’s information property list.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    infoDictionary

  • A dictionary, constructed from the bundle's Info.plist file, that contains information about the receiver. (read-only)

    Declaration

    Swift

    var infoDictionary: [NSObject : AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSDictionary *infoDictionary

    Discussion

    If the bundle does not contain an Info.plist file, this dictionary contains only private keys that are used internally by the NSBundle class. The NSBundle class may add extra keys to this dictionary for its own use. Common keys for accessing the values of the dictionary are CFBundleIdentifier, NSMainNibFile, and NSPrincipalClass.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the value associated with the specified key in the receiver's information property list.

    Declaration

    Swift

    func objectForInfoDictionaryKey(_ key: String) -> AnyObject?

    Objective-C

    - (id)objectForInfoDictionaryKey:(NSString *)key

    Parameters

    key

    A key in the receiver's property list.

    Return Value

    The value associated with key in the receiver's property list (Info.plist). The localized value of a key is returned when one is available.

    Discussion

    Use of this method is preferred over other access methods because it returns the localized value of a key when one is available.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The file URL of the receiver's subdirectory containing plug-ins. (read-only)

    Declaration

    Swift

    @NSCopying var builtInPlugInsURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *builtInPlugInsURL

    Discussion

    This is the appropriate path for modern application and framework bundles. This may not be a URL for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the receiver's subdirectory containing plug-ins. (read-only)

    Declaration

    Swift

    var builtInPlugInsPath: String? { get }

    Objective-C

    @property(readonly, copy) NSString *builtInPlugInsPath

    Discussion

    This is the appropriate path for modern application and framework bundles. This may not be a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The file URL of the receiver's executable file. (read-only)

    Declaration

    Swift

    @NSCopying var executableURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *executableURL

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the receiver's executable file. (read-only)

    Declaration

    Swift

    var executablePath: String? { get }

    Objective-C

    @property(readonly, copy) NSString *executablePath

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the file URL of the executable with the specified name in the receiver’s bundle.

    Declaration

    Swift

    func URLForAuxiliaryExecutable(_ executableName: String) -> NSURL?

    Objective-C

    - (NSURL *)URLForAuxiliaryExecutable:(NSString *)executableName

    Parameters

    executableName

    The name of an executable file.

    Return Value

    The file URL of the executable executableName in the receiver’s bundle.

    Discussion

    This method returns the appropriate path for modern application and framework bundles. This method may not return a URL for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns the full pathname of the executable with the specified name in the receiver’s bundle.

    Declaration

    Swift

    func pathForAuxiliaryExecutable(_ executableName: String) -> String?

    Objective-C

    - (NSString *)pathForAuxiliaryExecutable:(NSString *)executableName

    Parameters

    executableName

    The name of an executable file.

    Return Value

    The full pathname of the executable executableName in the receiver’s bundle.

    Discussion

    This method returns the appropriate path for modern application and framework bundles. This method may not return a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The file URL of the bundle’s subdirectory containing private frameworks. (read-only)

    Declaration

    Swift

    @NSCopying var privateFrameworksURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *privateFrameworksURL

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not be a URL for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the bundle’s subdirectory containing private frameworks. (read-only)

    Declaration

    Swift

    var privateFrameworksPath: String? { get }

    Objective-C

    @property(readonly, copy) NSString *privateFrameworksPath

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not contain a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The file URL of the receiver's subdirectory containing shared frameworks. (read-only)

    Declaration

    Swift

    @NSCopying var sharedFrameworksURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *sharedFrameworksURL

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not contain a URL for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the bundle’s subdirectory containing shared frameworks. (read-only)

    Declaration

    Swift

    var sharedFrameworksPath: String? { get }

    Objective-C

    @property(readonly, copy) NSString *sharedFrameworksPath

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not contain a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The file URL of the bundle’s subdirectory containing shared support files. (read-only)

    Declaration

    Swift

    @NSCopying var sharedSupportURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *sharedSupportURL

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not contain a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • The full pathname of the bundle’s subdirectory containing shared support files. (read-only)

    Declaration

    Swift

    var sharedSupportPath: String? { get }

    Objective-C

    @property(readonly, copy) NSString *sharedSupportPath

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not contain a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The file URL of the bundle’s subdirectory containing resource files. (read-only)

    Declaration

    Swift

    @NSCopying var resourceURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *resourceURL

    Discussion

    This property contains the appropriate path for modern application and framework bundles. This property may not contain a path for non-standard bundle formats or for some older bundle formats.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • Returns a localized version of the string designated by the specified key and residing in the specified table.

    Declaration

    Swift

    func localizedStringForKey(_ key: String, value value: String?, table tableName: String?) -> String

    Objective-C

    - (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName

    Parameters

    key

    The key for a string in the table identified by tableName.

    value

    The value to return if key is nil or if a localized string for key can’t be found in the table.

    tableName

    The receiver’s string table to search. If tableName is nil or is an empty string, the method attempts to use the table in Localizable.strings.

    Return Value

    A localized version of the string designated by key in table tableName. This method returns the following when key is nil or not found in table:

    • If key is nil and value is nil, returns an empty string.

    • If key is nil and value is non-nil, returns value.

    • If key is not found and value is nil or an empty string, returns key.

    • If key is not found and value is non-nil and not empty, return value.

    Discussion

    For more details about string localization and the specification of a .strings file, see “String Resources.”

    Using the user default NSShowNonLocalizedStrings, you can alter the behavior of localizedStringForKey:value:table: to log a message when the method can’t find a localized string. If you set this default to YEStrue (in the global domain or in the application’s domain), then when the method can’t find a localized string in the table, it logs a message to the console and capitalizes key before returning it.

    The following example cycles through a static array of keys when a button is clicked, gets the value for each key from a strings table named Buttons.strings, and sets the button title with the returned value:

    • - (void)changeTitle:(id)sender
    • {
    • static int keyIndex = 0;
    • NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
    • NSString *locString = [thisBundle
    • localizedStringForKey:assortedKeys[keyIndex++]
    • value:@"No translation" table:@"Buttons"];
    • [sender setTitle:locString];
    • if (keyIndex == MAXSTRINGS) keyIndex=0;
    • }

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • An array of numbers indicating the architecture types supported by the bundle’s executable. (read-only)

    Declaration

    Swift

    var executableArchitectures: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *executableArchitectures

    Discussion

    An array of NSNumber objects, each of which contains an integer value corresponding to a supported processor architecture. For a list of common architecture types, see the constants in Mach-O Architecture. If the bundle does not contain a Mach-O executable, this is nil.

    The bundle scans its Mach-O executable and returns all of the architecture types it finds. Because they are taken directly from the executable, the values may not always correspond to one of the well-known CPU types defined in Mach-O Architecture.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value indicating whether the bundle’s executable code could be loaded successfully.

    Declaration

    Swift

    func preflightAndReturnError(_ error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)preflightAndReturnError:(NSError **)error

    Parameters

    error

    On input, a pointer to an error object variable. On output, this variable may contain an error object indicating why the bundle’s executable could not be loaded. If no error would occur, this parameter is left unmodified. You may specify nil for this parameter if you are not interested in the error information.

    Return Value

    YEStrue if the bundle’s executable code could be loaded successfully or is already loaded; otherwise, NOfalse if the code could not be loaded.

    Discussion

    This method does not actually load the bundle’s executable code. Instead, it performs several checks to see if the code could be loaded and with one exception returns the same errors that would occur during an actual load operation. The one exception is the NSExecutableLinkError error, which requires the actual loading of the code to verify link errors.

    For a list of possible load errors, see the discussion for the loadAndReturnError: method.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Dynamically loads the bundle’s executable code into a running program, if the code has not already been loaded.

    Declaration

    Swift

    func load() -> Bool

    Objective-C

    - (BOOL)load

    Return Value

    YEStrue if the method successfully loads the bundle’s code or if the code has already been loaded, otherwise NOfalse.

    Discussion

    You can use this method to load the code associated with a dynamically loaded bundle, such as a plug-in or framework. Prior to OS X version 10.5, a bundle would attempt to load its code—if it had any—only once. Once loaded, you could not unload that code. In OS X version 10.5 and later, you can unload a bundle’s executable code using the unload method.

    You don’t need to load a bundle’s executable code to search the bundle’s resources.

    This method initializes the principal class in the bundle. Therefore, to add code you want executed after loading, override the initialize class method of the principal class.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Loads the bundle’s executable code and returns any errors.

    Declaration

    Swift

    func loadAndReturnError(_ error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)loadAndReturnError:(NSError **)error

    Parameters

    error

    On input, a pointer to an error object variable. On output, this variable may contain an error object indicating why the bundle’s executable could not be loaded. If no error occurred, this parameter is left unmodified. You may specify nil for this parameter if you are not interested in the error information.

    Return Value

    YEStrue if the bundle’s executable code was loaded successfully or was already loaded; otherwise, NOfalse if the code could not be loaded.

    Discussion

    If this method returns NOfalse and you pass a value for the error parameter, a suitable error object is returned in that parameter. Potential errors returned are in the Cocoa error domain and include the types that follow. For a full list of error types, see FoundationErrors.h.

    • NSFileNoSuchFileError - returned if the bundle’s executable file was not located.

    • NSExecutableNotLoadableError - returned if the bundle’s executable file exists but could not be loaded. This error is returned if the executable is not recognized as a loadable executable. It can also be returned if the executable is a PEF/CFM executable but the current process does not support that type of executable.

    • NSExecutableArchitectureMismatchError - returned if the bundle executable does not include code that matches the processor architecture of the current processor.

    • NSExecutableRuntimeMismatchError - returned if the bundle’s required Objective-C runtime information is not compatible with the runtime of the current process.

    • NSExecutableLoadError - returned if the bundle’s executable failed to load for some detectable reason prior to linking. This error might occur if the bundle depends on a framework or library that is missing or if the required framework or library is not compatible with the current architecture or runtime version.

    • NSExecutableLinkError - returned if the executable failed to load due to link errors but is otherwise alright.

    The error object may contain additional debugging information in its description that you can use to identify the cause of the error. (This debugging information should not be displayed to the user.) You can obtain the debugging information by invoking the error object’s description method in your code or by using the print-object command on the error object in gdb.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • loaded loaded Property

    The load status of a bundle.

    Declaration

    Swift

    var loaded: Bool { get }

    Objective-C

    @property(readonly, getter=isLoaded) BOOL loaded

    Discussion

    YEStrue if the bundle’s code is currently loaded, otherwise NOfalse.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 8.0 and later.

    See Also

    – load

  • Unloads the code associated with the receiver.

    Declaration

    Swift

    func unload() -> Bool

    Objective-C

    - (BOOL)unload

    Return Value

    YEStrue if the bundle was successfully unloaded or was not already loaded; otherwise, NOfalse if the bundle could not be unloaded.

    Discussion

    This method attempts to unload a bundle’s executable code using the underlying dynamic loader (typically dyld). You may use this method to unload plug-in and framework bundles when you no longer need the code they contain. You should use this method to unload bundles that were loaded using the methods of the NSBundle class only. Do not use this method to unload bundles that were originally loaded using the bundle-manipulation functions in Core Foundation.

    It is the responsibility of the caller to ensure that no in-memory objects or data structures refer to the code being unloaded. For example, if you have an object whose class is defined in a bundle, you must release that object prior to unloading the bundle. Similarly, your code should not attempt to access any symbols defined in an unloaded bundle.

    Special Considerations

    Prior to OS X version 10.5, code could not be unloaded once loaded, and this method would always return NOfalse. In OS X version 10.5 and later, you can unload a bundle’s executable code using this method.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns one or more localizations from the specified list that a bundle object would use to locate resources for the current user.

    Declaration

    Swift

    class func preferredLocalizationsFromArray(_ localizationsArray: [AnyObject]) -> [AnyObject]

    Objective-C

    + (NSArray *)preferredLocalizationsFromArray:(NSArray *)localizationsArray

    Parameters

    localizationsArray

    An array of NSString objects, each of which specifies the language ID for a localization that the bundle supports.

    Return Value

    An array of NSString objects containing the preferred localizations. These strings are ordered in the array according to the user's language preferences and are taken from the strings in the localizationsArray parameter.

    Discussion

    This method does not return all localizations in preference order but only those from which NSBundle would get localized content, typically either a single non-region-specific localization or a region-specific localization followed by a corresponding non-region-specific localization as a fallback.

    However, clients who want all localizations in preference order can make repeated calls, each time taking the top localizations out of the list of localizations passed in.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns the localizations that a bundle object would prefer, given the specified bundle and user’s language preferences.

    Declaration

    Swift

    class func preferredLocalizationsFromArray(_ localizationsArray: [AnyObject], forPreferences preferencesArray: [AnyObject]?) -> [AnyObject]

    Objective-C

    + (NSArray *)preferredLocalizationsFromArray:(NSArray *)localizationsArray forPreferences:(NSArray *)preferencesArray

    Parameters

    localizationsArray

    An array of NSString objects, each of which specifies the language ID for a localization that the bundle supports.

    preferencesArray

    An array of NSString objects containing the user's preferred localizations. If this parameter is nil, the method uses the user's localization preferences.

    Return Value

    An array of NSString objects, each of which identifies a localization in the receiver’s bundle. These strings are ordered in the array according to the specified preferences and are taken from the strings in the localizationsArray parameter. If none of the user-preferred localizations are available in the bundle, this method returns one of the bundle localizations.

    Discussion

    This method does not return all localizations in preference order but only those from which NSBundle would get localized content, typically either a single non-region-specific localization or a region-specific localization followed by a corresponding non-region-specific localization as a fallback.

    However, clients who want all localizations in preference order can make repeated calls, each time taking the top localizations out of the list of localizations passed in.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • An ordered list of preferred localizations contained in the bundle. (read-only)

    Declaration

    Swift

    var preferredLocalizations: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *preferredLocalizations

    Discussion

    An array of NSString objects containing language IDs for localizations in the bundle. The strings are ordered according to the user's language preferences and available localizations.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • The localization for the development language. (read-only)

    Declaration

    Swift

    var developmentLocalization: String? { get }

    Objective-C

    @property(readonly, copy) NSString *developmentLocalization

    Discussion

    This property corresponds to the value in the CFBundleDevelopmentRegion key of the bundle’s property list (Info.plist).

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • A list of all the localizations contained in the bundle. (read-only)

    Declaration

    Swift

    var localizations: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *localizations

    Discussion

    An array of NSString objects containing language IDs for all the localizations contained in the bundle.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • A dictionary with the keys from the bundle’s localized property list. (read-only)

    Declaration

    Swift

    var localizedInfoDictionary: [NSObject : AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSDictionary *localizedInfoDictionary

    Discussion

    This property uses the preferred localization for the current user when determining which resources to include. If the preferred localization is not available, this property chooses the most appropriate localization found in the bundle.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • These constants describe the CPU types that a bundle’s executable code may support.

    Declaration

    Swift

    var NSBundleExecutableArchitectureI386: Int { get } var NSBundleExecutableArchitecturePPC: Int { get } var NSBundleExecutableArchitectureX86_64: Int { get } var NSBundleExecutableArchitecturePPC64: Int { get }

    Objective-C

    enum { NSBundleExecutableArchitectureI386 = 0x00000007, NSBundleExecutableArchitecturePPC = 0x00000012, NSBundleExecutableArchitectureX86_64 = 0x01000007, NSBundleExecutableArchitecturePPC64 = 0x01000012 };

    Constants

    • NSBundleExecutableArchitectureI386

      NSBundleExecutableArchitectureI386

      Specifies the 32-bit Intel architecture.

      Available in iOS 2.0 and later.

    • NSBundleExecutableArchitecturePPC

      NSBundleExecutableArchitecturePPC

      Specifies the 32-bit PowerPC architecture.

      Available in iOS 2.0 and later.

    • NSBundleExecutableArchitectureX86_64

      NSBundleExecutableArchitectureX86_64

      Specifies the 64-bit Intel architecture.

      Available in iOS 2.0 and later.

    • NSBundleExecutableArchitecturePPC64

      NSBundleExecutableArchitecturePPC64

      Specifies the 64-bit PowerPC architecture.

      Available in iOS 2.0 and later.

  • This constant is provided in the userInfo dictionary of the NSBundleDidLoadNotification notification.

    Declaration

    Swift

    let NSLoadedClasses: NSString!

    Objective-C

    NSString * const NSLoadedClasses;

    Constants

    • NSLoadedClasses

      NSLoadedClasses

      An NSArray object containing the names (as NSString objects) of each class that was loaded

      Available in iOS 2.0 and later.

  • NSBundle posts NSBundleDidLoadNotification to notify observers which classes and categories have been dynamically loaded. When a request is made to an NSBundle object for a class (classNamed: or principalClass), the bundle dynamically loads the executable code file that contains the class implementation and all other class definitions contained in the file. After the module is loaded, the bundle posts the NSBundleDidLoadNotification.

    The notification object is the NSBundle instance that dynamically loads classes. The userInfo dictionary contains an NSLoadedClasses key.

    In a typical use of this notification, an object might want to enumerate the userInfo array to check if each loaded class conformed to a certain protocol (say, an protocol for a plug-and-play tool set); if a class does conform, the object would create an instance of that class and add the instance to another NSArray object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.