I saw a custom asset bundle in an iOS project I evaluated, so at least I know it\'s possible.
My issue is that I\'m using a CATiledLayer with about 22,000 tiles for
Here's how I got this to work: In Xcode create a new file | Resource | Settings Bundle. Then in the Finder select that bundle and choose Show Package Contents, and add whatever image files.
Then in the code reference an image this way:
NSString *imgName = @"bundlename.bundle/my-image.png";
UIImage *myImage = [UIImage imageNamed:imgName];
Creating a loadable bundle project is just like creating an application—you just need to pick the appropriate project template. To create a loadable bundle project, perform the following steps:
Build and run, in Xcode you will see the bundle file in your Products folder of Project Navigator. Right-click the bundle and select "Show in Finder".
Answer is stupidly simple
Make a folder in finder, add files to it, rename it to bundlename.bundle
drag into Xcode - success!
to access, use the form of PathToMainBundle+"/bundlename.bundle"
Here are the steps to create an asset or resource bundle (ex. FrameworkResources.bundle
) - it's surprisingly non-obvious. This is especially useful if you are creating static frameworks.
SDKROOT
) to "iOS'How to create a bundle
.bundle
(e.g. "New folder" -> "BundleName.bundle")PS: You can at any time right click the folder and hit "Show package content" in order to add, remove or modify any of the files.
How to add the bundle to Xcode
How to use the bundle
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"BundleName" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
NSString *resource = [bundle pathForResource:@"fileName" ofType:@"fileType"];
(Replace BundleName
, fileName
and fileType
with appropriate names)
Two other helpful bits of advice:
First, in order to see the contents of the bundle in Xcode you need to set its type in the File Inspector Utility Pane, to "Application Bundle". You still won't be able to copy to and from via Xcode. You'll need to use Terminal but Xcode will update it immediately.
Second, in order to use resources in the bundle here's a helpful snippet...
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"AquarianHarp" ofType:@"bundle"];
NSString *imageName = [[NSBundle bundleWithPath:bundlePath] pathForResource:@"trebleclef2" ofType:@"png"];
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:imageName];
As mentioned in my comment above, you needn't actually load the bundle (you can't as it's not executable) and the ofType
needs to match the case of your actual file for it to work on the device. It will work either way in simulator so don't be fooled by this red herring!
Finally, you don't need to put your resources in the "Resources" subfolder inside the bundle. It seems you can use an arbitrary layout but there may be unknown performance implications.