What is bundle in iOS development?

Source: Internet
Author: User
The following code has been written more or less by beginners of iOS development, regardless of their own or pasted code.

[[Nsbundle mainbundle] pathforresource: @ "somefilename" oftype: @ "yourfileextension"];

[Yourviewcontroller initwithnibname: "yourviewcontroller" Bundle: Nil];


But you know what bundle is here ?! Bundle is a special directory in which internal structures are organized according to standard rules.
IOS applications are encapsulated by bundle, and the corresponding bundle type is application. Normally, the target (the application we developed) compiled by xcode is used ), it is actually a bundle of the application type, that is, a folder! However, the finder will display the bundle as a file because the bundle itself is also a package, and the MAC system will treat all the packages as a file and display them to users, this prevents program files from being damaged or lost due to misoperations. The difference between bundle and package is not described here. The bundle mentioned later in this article will be regarded as package by the MAC system. Now we know that the application we developed will eventually become a bundle, which makes it easy to understand why many resource file loads are mostly carried out through bundle, file loading from bundle is actually carried out through the folder where the application is located. But then we will have several questions: 1. Why not use the file path directly to read the resource file? 2. Why does the pathforresource: oftype: method still exist? Is it hard to say that we cannot determine where these files are during development?

In fact, we can use the path of the file system to access resource files, but when we want to internationalize the app, we need to load the corresponding files in different languages and regions by ourselves. While some resource files are public and some need to be internationalized, code maintenance is particularly confusing for developers. For IOS developers, bundle can easily make their applications internationalized and load different resource files in different regions in different languages, display different language characters. To achieve this, you only need to store resource files in strict accordance with bundle requirements, without writing a lot of code to determine the regional language. The following method is simple. You only need to create the corresponding "localized folder". For example, you need to make the image "pic.png" display different content in Chinese and English, you only need to create two local folders Zh. lproj and en. lproj, put "pic.png" with the same name but different content.
Related Article

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.