IOS NSBundle Use, note the difference between mainbundle and custom bundles

Source: Internet
Author: User

1, [NSBundle Mainbundle], the folder is actually group, such as the left side of the tree file Manager

After the build, the file is copied directly to the root directory, so the Read method should be:

NSString*earth = [[NSBundle mainBundle] pathForResource:@"Brad Cox"ofType:@"png"];

2, when using the folder, build results

Still use the same method, do not need to set the folder path

Indirectory parameters are optional
NSString *earth = [[NSBundle mainbundle] pathforresource:@ "Matthijs" oftype:@ "png" indirectory:@ "Images/MoreImages"]; NSString *earth = [[NSBundle mainbundle] pathforresource:@ "Matthijs" oftype:@ "PNG"];

After compiling, mainbundle resources are placed under RootFolder, so you can access them directly, not specify the internal path

3. Use other bundles

NSString *resourcebundle = [[NSBundle mainbundle] pathforresource:@ "Resources" oftype:@ "bundle"]; NSLog (@ "ResourceBundle:%@", resourcebundle);

  

Using the custom bundle to access the internal subfolders, you need to specify the Indirectory parameter, this mainbundle is different, why?

  

Note: Sincebundles other than the main bundle can has folders embedded inside them, to accessfiles inside folders of a Bundl e other than the main bundle it's best for use the pathForResource:ofType:inDirectory:method of NSBundle to explicitly SP Ecify the folder Inwhich a specific file/resource exists.

Original address: http://www.cnblogs.com/iihe602/archive/2013/01/17/2865280.html

IOS NSBundle Use, note the difference between mainbundle and custom bundles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.