Objective-C 中的 NSBundle 和 mainBundle 是什么?
关于iOS上的Objective-C应用程序,我在Apple开发者网站上阅读了一些示例程序,发现几乎所有应用程序都包含一个名为 'NSBundle' 和 'mainBundle',我实在不明白这个词的意思。那是什么?
Regarding Objective-C on iOS application, I read some sample program in the Apple developer website and I found that almost all of the applications contains a word called 'NSBundle' and 'mainBundle', and I really don't understand the meaning of this word. What is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
捆绑包是 Mac OS X 上用于打包软件的结构。应用程序、框架和插件都是不同类型的捆绑包。如果您愿意,捆绑包可能包含可执行代码、资源、头文件和其他内容(包括其他捆绑包)。
捆绑包被实现为具有已定义结构的目录树。应用程序、框架和插件在树结构上都有自己的变体。然而,对于 Finder 来说,捆绑包看起来就像单个文件。
主捆绑包只是正在运行的应用程序的捆绑包。例如,Apple 邮件程序的主包是 /Applications/Mail.app。
A bundle is a structure used for packaging software on Mac OS X. Applications, frameworks and plug-ins are all different kinds of bundles. Bundles may contain executable code, resources, header files and other stuff (including other bundles) if you so wish.
Bundles are implemented as directory trees with a defined structure. Applications, frameworks and plug-ins each have their own variation on the structure of the tree. However, to the Finder, bundles look like single files.
The main bundle is simply the bundle of the application that is running. So, for instance, the main bundle of the Apple mail program is /Applications/Mail.app.
假设我们的代码是:
我们在Xcode中创建subject.plist(文件>新建>新文件>iOS>资源>属性列表)并将其复制到我们的支持文件夹中。
当我们不知道 iOS 设备上安装的文件在哪里时,这确实是一种获取它们的方法。这是获取
subject.plist
文件的一种方法,该文件是我们应用程序的内部 Bundle 或内部包的一部分。我们无法直接访问 iOS 设备上的文件系统,因此这是我们获取自己资产的方式。Suppose our code is:
We create subject.plist in Xcode (File> new> new file> iOS> resource> property list) and copy it into our supporting folder.
This is really a way of getting to files installed on the iOS device when we do not know where they are. It's a way to obtain our
subject.plist
file, which is a part of the internal Bundle or internal package for our application. We don't have direct access to a file system on an iOS device, so this is the way we get hold of our own assets.苹果有一个关于捆绑包的很好的文档。 捆绑编程指南
There is a good apple documentation about bundles. Bundle Programming Guide