Finding the File in the Application Bundle

To load the texture you must first find the texture’s file in the application bundle. Finding the file requires you to call two functions. The first function to call is CFBundleGetMainBundle(), which returns the application’s bundle.

CFBundleRef gameBundle = CFBundleGetMainBundle();

The second function to call is CFBundleCopyResourceURL(), which returns the file’s location in the bundle. This function takes four arguments. The first argument is the bundle you retrieved by calling CFBundleGetMainBundle(). The second argument is the file’s name. The third argument is the file’s extension. The final argument is a subdirectory in the bundle where the operating system should search for the file. You can pass NULL as the final argument, which tells the operating system to search the entire bundle for the file.

CFBundleRef gameBundle;
CFStringRef filename;
CFStringRef fileExtension;
CFStringRef subdirectory;
CFURLRef fileLocation;

fileLocation = CFBundleCopyResourceURL(gameBundle, filename, 
        fileExtension, subdirectory);

Suppose you want to load a file named Background.png. There are two ways you can call CFBundleCopyResourceURL(). First, you can use Background as the file name and png as the extension. Second, you can use Background.png as the file name and NULL as the extension. Both methods work. The first method is slightly faster if you have lots of files in your application bundle.

Next (Creating a Data Reference)

Previous (Introduction)