What's a bundle in iOS development?

Source: Internet
Author: User

Beginner iOS Development students, whether it is written by themselves, or pasted code, more or less have written the following code

[[NSBundle Mainbundle] pathforresource:@ "Somefilename" oftype:@ "yourfileextension"];

[Yourviewcontroller initwithnibname: "Yourviewcontroller" bundle:nil];

But you know what the bundle here is?!

The bundle is simply a special catalogue of internal structures organized in accordance with standard Rules.


iOS applications are encapsulated through bundles, the corresponding bundle type is the application type, usually we compile the target through Xcode (that is, we develop the application), is actually a application type bundle, That's a folder! But the finder will show this bundle as a file to us, actually because the bundle itself is a package, and the Mac system treats all the package as a file, shows it to the user, This prevents the user from misoperation and causes the program file to be corrupted or lost. As to the difference between bundles and package, it is not here to explain that the bundles described later in this article will be considered by the MAC system as the package.

Now that we know that the application we developed, and eventually become a bundle, it is not difficult to understand why many of the resource files are loaded through bundles, and the file load from the bundle is actually loaded by the application's own folder.

But then we have several questions:

1 Why not use the file path directly to read the resource file?

2 Why still exist Pathforresource:oftype: This method, we are not in the development of the time to determine where these files?



In fact, we can use the path of the file system to access the resource files, but when we want to do the internationalization of the app, we need to implement different languages, regions to load the corresponding files, and in some of the resource files common, some need internationalization, for developers, Code maintenance is especially confusing.

and bundle for iOS developers, the biggest convenience is to be very simple to let their own application internationalization, in different languages different regions, loading different resource files, display different language text, and achieve these only need we strictly according to the requirements of the bundle of resources file storage can be, Rather than writing a lot of code to judge the locale language. Follow the method is also very simple, just need us to create the corresponding "Localization folder", for example, we want to let the picture "Pic.png" in Chinese and English display different content, only need to create two localization folders Zh.lproj and En.lproj, respectively, put the same name but different content " Pic.png "can.

Specific ways to internationalize your application will be described later in the article.

What's a bundle in iOS development?

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.