### Localized Info.plist Strings Example Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes This example demonstrates how to localize strings within an application's Info.plist file using an InfoPlist.strings file. It shows sample key-value pairs for localization, specifically for the German language. ```properties CFBundleDisplayName = "TextEdit"; NSHumanReadableCopyright = "Copyright © 1995-2009 Apple Inc.\nAlle Rechte vorbehalten."; ``` -------------------------------- ### Framework Bundle Structure Example Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes Illustrates the typical hierarchical structure of a macOS framework bundle, including versioned directories and symbolic links for accessing the latest framework code and resources. ```text MyFramework.framework/ MyFramework -> Versions/Current/MyFramework Resources -> Versions/Current/Resources Versions/ A/ MyFramework Headers/ MyHeader.h Resources/ English.lproj/ InfoPlist.strings Info.plist Current -> A ``` -------------------------------- ### iOS Application Bundle Structure Example Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes This example illustrates the typical file and directory structure of an iOS application bundle, differentiating between nonlocalized and localized resources. It shows the placement of executable files, Info.plist, icons, nib files, and localized strings. ```text MyApp.app/ Info.plist MyApp Default.png Icon.png Hand.png MainWindow.nib MyAppViewController.nib WaterSounds/ Water1.aiff Water2.aiff en.lproj/ CustomView.nib bird.png Bye.txt Localizable.strings jp.lproj/ CustomView.nib bird.png Bye.txt Localizable.strings ``` -------------------------------- ### Application Bundle Structure Example Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes This snippet illustrates a typical file and directory structure for a Mac application bundle, showcasing the organization of localized and non-localized resources within the Contents/Resources directory. ```tree MyApp.app/ Contents/ Info.plist MacOS/ MyApp Resources/ Hand.tiff MyApp.icns WaterSounds/ Water1.aiff Water2.aiff en.lproj/ MyApp.nib bird.tiff Bye.txt InfoPlist.strings Localizable.strings CitySounds/ city1.aiff city2.aiff jp.lproj/ MyApp.nib bird.tiff Bye.txt InfoPlist.strings Localizable.strings CitySounds/ city1.aiff city2.aiff ``` -------------------------------- ### Loadable Bundle Structure Example Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes This illustrates a typical hierarchical layout for a loadable bundle. It includes the essential 'Contents' directory, which contains the 'Info.plist' file, the 'MacOS' directory for the executable code, and the 'Resources' directory for localization and assets. ```text MyLoadableBundle.bundle/ Contents/ Info.plist MacOS/ MyLoadableBundle Resources/ Lizard.jpg MyLoadableBundle.icns en.lproj/ MyLoadableBundle.nib InfoPlist.strings jp.lproj/ MyLoadableBundle.nib InfoPlist.strings ``` -------------------------------- ### Get Main Bundle in Core Foundation (C) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Obtains a reference to the main application bundle using the `CFBundleGetMainBundle` function. This method is suitable for C-based applications utilizing Core Foundation. It's crucial to check if the returned `CFBundleRef` is NULL, as it may fail if the program is not bundled or if launch path information is missing. ```C CFBundleRef mainBundle; // Get the main bundle for the app mainBundle = CFBundleGetMainBundle(); ``` -------------------------------- ### Get Core Foundation Bundles from Directory Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieve an array of bundle references from a specified directory. This function iterates through the directory and returns `CFBundleRef` objects for all found bundles. It's particularly useful for loading plug-ins from a known location like the `PlugIns` directory. Ensure to release the `CFURLRef` and `CFArrayRef` when finished. ```c CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef plugInsURL; CFArrayRef bundleArray; // Get the URL to the application’s PlugIns directory. plugInsURL = CFBundleCopyBuiltInPlugInsURL(mainBundle); // Get the bundle objects for the application’s plug-ins. bundleArray = CFBundleCreateBundlesFromDirectory( kCFAllocatorDefault, plugInsURL, NULL ); // Release the CF objects when done with them. CFRelease( plugInsURL ); CFRelease( bundleArray ); ``` -------------------------------- ### Load C Function Pointer from Bundle (Core Foundation) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves a function pointer from a bundle's executable file using CFBundleGetFunctionPointerForName. Requires a CFBundleRef and the function name as a CFString. Returns a void pointer to the function or NULL if not found. The example demonstrates calling the retrieved function. ```Objective-C // Function pointer. AddOneFunctionPtr addOne = NULL; // Value returned from the loaded function. long result = 0; // Get a pointer to the function. addOne = (void*)CFBundleGetFunctionPointerForName( myBundle, CFSTR("addOne") ); // If the function was found, call it with a test value. if (addOne) { // This should add 1 to whatever was passed in result = addOne ( 23 ); } ``` -------------------------------- ### Get Bundle Info Dictionary (Core Foundation) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves the non-localized key-value pairs from a bundle's information property list using CFBundleGetInfoDictionary. The result is a CFDictionaryRef, from which specific values can be extracted using CFDictionaryGetValue. ```objective-c CFDictionaryRef bundleInfoDict; CFStringRef myPropertyString; // Get an instance of the non-localized keys. bundleInfoDict = CFBundleGetInfoDictionary( myBundle ); // If we succeeded, look for our property. if ( bundleInfoDict != NULL ) { myPropertyString = CFDictionaryGetValue( bundleInfoDict, CFSTR("MyPropertyKey") ); } ``` -------------------------------- ### Get Main Bundle in Cocoa (Objective-C) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves a reference to the main application bundle using the `mainBundle` class method of the `NSBundle` class. This is the standard method for Cocoa applications. Ensure the returned value is not NULL before use. ```Objective-C NSBundle* mainBundle; // Get the main bundle for the app. mainBundle = [NSBundle mainBundle]; ``` -------------------------------- ### Get Bundle Version Number (Core Foundation) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves the bundle's version number using the CFBundleGetVersionNumber function. The version is returned as an unsigned long integer. This is useful for compatibility checks. ```objective-c #define kMyBundleVersion1 0x01008000 // This is the ‘vers’ resource style value for 1.0.0 UInt32 bundleVersion; // Look for the bundle’s version number. bundleVersion = CFBundleGetVersionNumber( mainBundle ); // Check the bundle version for compatibility with the app. if (bundleVersion < kMyBundleVersion1) return (kErrorFatalBundleTooOld); ``` -------------------------------- ### Get Bundle Directory Paths with Cocoa NSBundle Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves paths to the top-level bundle directory and its key subdirectories using the NSBundle class in Cocoa. These methods return NSString objects, compatible with other NSBundle methods or convertible to NSURL. ```Objective-C NSBundle *bundle = [NSBundle mainBundle]; NSURL *bundleURL = [bundle bundleURL]; NSString *bundlePath = [bundle bundlePath]; NSURL *builtInPlugInsURL = [bundle builtInPlugInsURL]; NSString *builtInPlugInsPath = [bundle builtInPlugInsPath]; NSURL *resourceURL = [bundle resourceURL]; NSString *resourcePath = [bundle resourcePath]; NSURL *sharedFrameworksURL = [bundle sharedFrameworksURL]; NSString *sharedFrameworksPath = [bundle sharedFrameworksPath]; NSURL *sharedSupportURL = [bundle sharedSupportURL]; NSString *sharedSupportPath = [bundle sharedSupportPath]; ``` -------------------------------- ### Get Bundle Directory Paths with Core Foundation CFBundle Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Obtains the URLs for the bundle itself and its key subdirectories using Core Foundation's CFBundle functions. These functions return CFURLRef opaque types, which can be converted to CFStringRef for use with other Core Foundation routines. ```C CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle); CFURLRef builtInPlugInsURL = CFBundleCopyBuiltInPlugInsURL(mainBundle); CFURLRef resourcesDirectoryURL = CFBundleCopyResourcesDirectoryURL(mainBundle); CFURLRef sharedFrameworksURL = CFBundleCopySharedFrameworksURL(mainBundle); CFURLRef supportFilesDirectoryURL = CFBundleCopySupportFilesDirectoryURL(mainBundle); // To get a CFStringRef from a CFURLRef: // CFStringRef bundlePathString = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); // Remember to release the CFURLRef objects when done // CFRelease(bundleURL); // CFRelease(builtInPlugInsURL); // CFRelease(resourcesDirectoryURL); // CFRelease(sharedFrameworksURL); // CFRelease(supportFilesDirectoryURL); ``` -------------------------------- ### Creating Document Package Manually (BSD File System) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages This method is suitable for command-line tools or applications not using higher-level Objective-C frameworks. It involves creating a directory with the appropriate filename extension using standard BSD file system routines. The Finder uses this extension to recognize the directory as a package. ```c // Example using BSD file system routines to create a directory (package) // #include // #include // #include const char *packageName = "MyDocument.mydocpkg"; if (mkdir(packageName, 0755) == 0) { // Directory created successfully // Now create files inside this directory using open(), write(), close() } else { // Handle error } ``` -------------------------------- ### Registering Document Package Type in Info.plist Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages This snippet shows how to register a document as a package by modifying the application's Info.plist file. The LSTypeIsPackage key, when present with an appropriate value, instructs Finder and Launch Services to treat directories with a specific file extension as packages. ```plist CFBundleDocumentTypes CFBundleTypeName My Document Package CFBundleTypeExtensions mydocpkg LSTypeIsPackage ``` -------------------------------- ### Basic macOS Application Bundle Structure Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes This snippet illustrates the fundamental directory layout of a typical macOS application bundle. It shows the root application directory and its primary subdirectories within the `Contents` folder. ```text MyApp.app/ Contents/ Info.plist MacOS/ Resources/ ``` -------------------------------- ### Loading CFM Code with CFBundleRef/CFPlugInRef Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles The NSBundle class cannot load Code Fragment Manager (CFM) code. To load CFM-based code or plugins, use the Core Foundation functions associated with CFBundleRef or CFPlugInRef opaque types. This technique allows loading CFM-based plugins from a Mach-O executable. ```objectivec // Example using CFBundleRef (requires CoreFoundation framework) CFBundleRef myBundle = CFBundleCreate(kCFAllocatorDefault, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/path/to/your/bundle.bundle"), kCFURLPOSIXPathStyle, true)); if (myBundle) { // Load a symbol or function from the bundle // ... CFRelease(myBundle); } ``` -------------------------------- ### Creating Document Package Manually (NSFileManager) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages This approach uses the NSFileManager class from the Foundation framework for creating document packages. It is an alternative to raw BSD file system routines for applications that leverage the Foundation framework, allowing for manual creation of the package directory and its contents. ```objective-c // Example using NSFileManager to create a directory (package) NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *packageURL = [NSURL fileURLWithPath:@"MyDocument.mydocpkg"]; NSError *error; if ([fileManager createDirectoryAtURL:packageURL withIntermediateDirectories:NO attributes:nil error:&error]) { // Directory created successfully // Use fileManager to create files inside this directory } else { // Handle error } ``` -------------------------------- ### Loading Java Code with NSBundle Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles When loading bundles that contain Java code, it is recommended to always use the NSBundle class. Avoid using the functions associated with the CFBundleRef opaque type for Java code. ```objectivec // Example using NSBundle to load a bundle with Java code NSBundle *javaBundle = [NSBundle bundleWithPath:@"/path/to/your/java.bundle"]; [javaBundle load]; // Access Java classes or methods via appropriate Java interop mechanisms // ... ``` -------------------------------- ### Creating Document Package with NSFileWrapper (Objective-C) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages For Cocoa applications, NSFileWrapper is the recommended method for creating document packages. It integrates seamlessly with NSDocument for reading and writing document contents. This approach simplifies handling document packages, especially in iOS 4.0 and later. ```objective-c // Example using NSFileWrapper for creating a document package // Assumes you have NSDocument and NSFileWrapper available. // Refer to NSFileWrapper Class Reference for detailed usage. NSFileWrapper *directoryWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappersInsideURL:directoryURL originalContentsDirectoryURL:nil error:&error]; // ... add file wrappers for contents ... [directoryWrapper writeToURL:packageURL options:0 originalContentsURL:nil error:&error]; ``` -------------------------------- ### Bundle Structure for Localized Resources Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes Illustrates a typical directory structure for a macOS application bundle that includes localized resources. It shows region-specific (.lproj) and language-specific (.lproj) directories, highlighting how they contain subsets of resources found in the general language directory. ```text Resources/ MyApp.icns en_GB.lproj/ MyApp.nib bird.tiff Localizable.strings en_US.lproj/ MyApp.nib Localizable.strings en.lproj/ MyApp.nib bird.tiff Bye.txt house.jpg InfoPlist.strings Localizable.strings CitySounds/ city1.aiff city2.aiff ``` -------------------------------- ### Loading Objective-C Code: NSBundle vs. CFBundleRef Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles For Objective-C code in macOS v10.5+, you can use either NSBundle or CFBundleRef. NSBundle loads globally with lazy symbol binding and triggers NSBundleDidLoadNotification. CFBundleRef loads privately with immediate symbol binding and does not generate notifications. ```objectivec // Using NSBundle (global load, lazy binding, notifications) NSBundle *objcBundleNS = [NSBundle bundleWithPath:@"/path/to/your/objc.bundle"]; [objcBundleNS load]; // Observe NSBundleDidLoadNotification // Using CFBundleRef (private load, immediate binding, no notifications) CFBundleRef objcBundleCF = CFBundleCreate(kCFAllocatorDefault, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/path/to/your/objc.bundle"), kCFURLPOSIXPathStyle, true)); if (objcBundleCF) { CFBundleLoadExecutable(objcBundleCF); // ... CFRelease(objcBundleCF); } ``` -------------------------------- ### Access Core Foundation Bundle by Path Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Create a Core Foundation bundle reference from a file system path. This requires converting the path to a `CFURLRef` using `CFURLCreateWithFileSystemPath` and then creating the bundle with `CFBundleCreate`. Remember to release the URL and bundle references when no longer needed. ```c CFURLRef bundleURL; CFBundleRef myBundle; // Make a CFURLRef from the CFString representation of the // bundle’s path. bundleURL = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, CFSTR("/Library/MyBundle.bundle"), kCFURLPOSIXPathStyle, true ); // Make a bundle instance using the URLRef. myBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL ); // You can release the URL now. CFRelease( bundleURL ); // Use the bundle... // Release the bundle when done. CFRelease( myBundle ); ``` -------------------------------- ### Marking C++ Symbols for Bundles Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles When loading C++ code from a bundle, marking symbols with `extern “C”` is recommended. This helps avoid issues with C++ name mangling, making symbols easier to identify when using NSBundle or Core Foundation CFBundleRef functions. ```cpp #ifdef __cplusplus extern "C" { #endif // Your C++ function declarations here void myFunction(); #ifdef __cplusplus } #endif ``` -------------------------------- ### Find Multiple Resource URLs with CFBundleRef (Core Foundation) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves all resource files of a specified type within a given directory of a bundle. It returns a CFArrayRef containing CFURLRefs for the found resources. The 'directory' parameter specifies the subdirectory to search. ```C CFArrayRef birdURLs; // Find all of the JPEG images in a given directory. birdURLs = CFBundleCopyResourceURLsOfType( mainBundle, CFSTR("jpg"), CFSTR("BirdImages") ); ``` -------------------------------- ### Loading Device-Specific Images in iOS Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Demonstrates how to load an image resource, allowing the system to automatically select the appropriate device-specific version (iPhone/iPod touch or iPad) based on the device it's running on. If a device-specific version is not found, it falls back to the non-localized version. ```objectivec UIImage* anImage = [UIImage imageNamed:@"MyImage.png"]; ``` -------------------------------- ### Customizing NSDocument for Document Packages (Objective-C) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages When working with document packages in a Cocoa application, you must customize your NSDocument subclass. Instead of the traditional readFromData:ofType:error: and dataOfType:error: methods, use readFromFileWrapper:ofType:error: and fileWrapperOfType:error: to handle the package structure. ```objective-c // In your NSDocument subclass: - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError { // Custom logic to read contents from the NSFileWrapper return YES; } - (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError **)outError { // Custom logic to create and return an NSFileWrapper for the document return [[NSFileWrapper alloc] initRegularFileWithData:someData]; // Placeholder } ``` -------------------------------- ### Compile with No Constant CF Strings Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents When compiling bundles that are intended to be unloaded, it is recommended to use the `-fno-constant-cfstrings` compiler flag. This flag ensures that string constants are handled appropriately, preventing potential crashes due to invalid references after the executable is unloaded. ```bash clang -fno-constant-cfstrings -o myBundle.bundle myBundle.c ``` -------------------------------- ### Find Single Resource URL with CFBundleRef (Core Foundation) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Obtains a CFURLRef for a single resource within a bundle, identified by its name and type. The 'subdirectory' parameter can be NULL if the resource is in the main bundle's resource directory. ```C CFURLRef seagullURL; // Look for a resource in the main bundle by name and type.seagullURL = CFBundleCopyResourceURL( mainBundle, CFSTR("Seagull"), CFSTR("jpg"), NULL ); ``` -------------------------------- ### Access Cocoa Bundle by Path Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Obtain a reference to a Cocoa bundle by providing its full path. This method is useful when the exact location of the bundle is known. It utilizes the `bundleWithPath:` class method of the `NSBundle` class. ```objective-c NSBundle* myBundle; // Obtain a reference to a loadable bundle. myBundle = [NSBundle bundleWithPath:@"/Library/MyBundle.bundle"]; ``` -------------------------------- ### Find Multiple Resource Paths with NSBundle (Objective-C) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Finds all resource files of a specified type within an NSBundle's resource directory. It returns an NSArray containing the paths. If 'inDirectory' is nil, it searches the top-level resource directory. ```Objective-C NSBundle* myBundle = [NSBundle mainBundle]; NSArray* myImages = [myBundle pathsForResourcesOfType:@"jpg" inDirectory:nil]; ``` -------------------------------- ### Compile with Constant CF Strings Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Compiling a bundle with a minimum deployment target of macOS v10.2 or later, or explicitly with the `-fconstant-cfstrings` flag, causes the compiler to generate truly constant strings for `CFSTR("...")`. While this offers benefits, it can lead to crashes if these strings are referenced after the bundle is unloaded. ```bash clang -fconstant-cfstrings -o myBundle.bundle myBundle.c ``` -------------------------------- ### Find Single Resource Path with NSBundle (Objective-C) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves the path to a single resource file within an NSBundle. It requires the resource name and its type (file extension). If the resource is not found, it returns nil. ```Objective-C NSBundle* myBundle = [NSBundle mainBundle]; NSString* myImage = [myBundle pathForResource:@"Seagull" ofType:@"jpg"]; ``` -------------------------------- ### Load Objective-C Principal Class from Bundle (NSBundle) Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Loads the principal class defined in a bundle's Info.plist using NSBundle's principalClass method. If successful, it creates an instance of that class. This is useful for factory patterns or when specific naming conventions are not desired. ```Objective-C - (void)loadBundle:(NSString*)bundlePath { Class exampleClass; id newInstance; NSBundle *bundleToLoad = [NSBundle bundleWithPath:bundlePath]; if (exampleClass = [bundleToLoad principalClass]) { newInstance = [[exampleClass alloc] init]; // [newInstance doSomething]; } } ``` -------------------------------- ### Locate Bundle by Identifier in Core Foundation Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves a CFBundleRef object using its unique bundle identifier. This function is part of the Core Foundation framework and is used to find bundles that have already been loaded into memory. It requires a string constant representing the bundle identifier. ```c CFBundleRef requestedBundle; // Look for a bundle using its identifier requestedBundle = CFBundleGetBundleWithIdentifier( CFSTR("com.apple.Finder.MyGetInfoPlugIn") ); ``` -------------------------------- ### Unload Core Foundation Bundle Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents This function is used to unload a bundle that was loaded using Core Foundation. It's important to manage constant strings correctly when compiling bundles that might be unloaded to avoid invalid references and crashes. ```c CFBundleUnloadExecutable(myBundle); ``` -------------------------------- ### Locate Bundle by Identifier in Cocoa Source: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents Retrieves an NSBundle object using its unique bundle identifier. This method is efficient for accessing bundles already loaded into memory. It takes a string representing the bundle identifier as input and returns an NSBundle object or nil if not found. ```objective-c NSBundle* myBundle = [NSBundle bundleWithIdentifier:@"com.apple.myPlugin"]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.