Friday, 1 April 2016

Create Resource Bundle in iOS

Create Resource Bundle in iOS with Images, 

XIBs, Audios, Videos, etc.



Many times with Custom Frameworks we need to provide Resources as well, so we can bind them in bundle and can easily pass with Frameworks, see more about creating iOS Framework here.

Step 1: Create new project


Create new project, select Project template as "Utility Application" (Suppose Project name : "iOSFramework") 


Step 2: Create new target

Navigate to main xCode menu, File => New => Target
Select "Framework & Library" from left panel and select "Bundle" like shown in below snap!

Named something relevant to your framework name, in this tutorial I named it "ResourceBundle".


Creating Bundle


Creating Bundle


Step 3: Remove files .plist,.pch and language

  • Navigate to project navigator, you can find group for "ResourceBundle"
  • Remove .plist, .pch and language files of "ResourceBundle" only.
  • Make SURE you are not removing for main project's it must be your bundle which you just created.


Step 4: Configuration changes in build settings of Bundle

When the resources bundle target is added, it will default to being set up with a Mac OS X build target. This is wrong because we want an iOS one so you just need to change the relevant settings to whatever you want your iOS target to be (probably “Latest iOS”). Use the screenshot below to guide you in doing this.

  • Base SDK: Latest iOS (iOS X.X).
Step 5: Build Phase => Link Binary With Libraries => remove all references

Step 6: Add Resources

  • Right Click on ResourceBundle Folder(Group), Select Add files to <Project_Name>, Select Resources you would like add in bundle, in our case I added apple.png and tester.mp3
  • Make sure "Add to targets" has our bundle selected, in our case it's "ResourceBundle", see below snap!

Adding Resources

Step 7: Build Bundle
Build bundle target scheme for "iOS Device" (Cmd + B)

Build Bundle

Step 8: Grab Bundle from Products folder

From project navigator scroll down to Products folder and locate "ResourceBundle.bundle" file and right click on it and select "Show in finder" copy it and keep it at safe place to reuse it with any other project.

Grab Bundle


How to use Bundle with any other Project?

Drag bundle in any of the project see below example for Image and Audio



Thanks for reading the Article!

No comments:

Post a Comment