Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

1. The Basics > 1.28. Loading Data From Other Bundles

1.28. Loading Data From Other Bundles

Problem

You have included a few images or other resources in a separate bundle inside your main bundle and you would like to access those resources at runtime.

Solution

Find the path to your bundle at runtime using the pathForResource:ofType: method of your main bundle. Once you have the path to your bundle, simply access it using the bundleWithPath: class method of NSBundle.

Note

Before continuing with this recipe, please follow the instructions in Recipe 1.26 to create a bundle called Resources.bundle and place it inside your main bundle.

Discussion

If you have followed the instructions in Recipe 1.26, you now have a bundle called Resources.bundle inside this bundle you have a folder called Images. Let’s now put an image inside this folder. After I placed an image called AlanSugar.png into the bundle Figure 1-35 shows what the bundle contains.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial