Xcode:哪些文件需要成为我的目标的成员?(目标会员)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18114413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:40:49  来源:igfitidea点击:

Xcode: Which files need to be members of my target? (Target Membership)

iosxcode

提问by T Blank

I'm developing an iPhone app in Xcode 4.6.2 that only has one target, and I've noticed that some important files are not members of my target. None of my custom header files are part of the target membership, nor is my Info.plist, my Prefix header, or the product "MyApp.app."

我正在 Xcode 4.6.2 中开发一个只有一个目标的 iPhone 应用程序,我注意到一些重要的文件不是我的目标的成员。我的自定义头文件都不是目标成员的一部分,我的 Info.plist、Prefix 头或产品“MyApp.app”也不是。

The way I understand targets, these files certainly need to be members of the target.

按照我理解目标的方式,这些文件当然需要是目标的成员。

My question is: why aren't these files members of my target?

我的问题是:为什么这些文件不是我的目标成员?

After searching around on SO, similar questions have yielded some insight, but not a complete answer to that question. The insight I've gathered is:

在搜索了 SO 之后,类似的问题已经产生了一些见解,但不是该问题的完整答案。我收集到的见解是:

  1. Header files are not members of your target because they get linked in the "Copy Headers" Build Phase.

    • This sounds reasonable, but I don't have a Copy Headers Build Phase
  2. Info.plist and Prefix.pch aren't members of the target because Info.plist gets linked in the "Copy Bundle Resources" Build Phase, and the Info.plist contains a key/value entry that points to the prefix header (Prefix.pch)

    • I'm not positive that this is actually how it works
  1. 头文件不是目标的成员,因为它们在“复制头”构建阶段被链接。

    • 这听起来很合理,但我没有复制标题构建阶段
  2. Info.plist 和 Prefix.pch 不是目标的成员,因为 Info.plist 在“复制捆绑资源”构建阶段获得链接,并且 Info.plist 包含一个键/值条目,指向前缀标头 (Prefix.plist)。 pch)

    • 我不确定这实际上是如何工作的

回答by Jim

Header files are what other source files reference so that they know what the interface for a class is. They aren't needed as part of the binary itself, so they don't need to be included in the final product.

头文件是其他源文件所引用的,以便它们知道类的接口是什么。它们不需要作为二进制文件本身的一部分,因此它们不需要包含在最终产品中。

Info.plistis a special case as it defines the application bundle itself, so it is processed separately.

Info.plist是一种特殊情况,因为它定义了应用程序包本身,因此它被单独处理。

Generally speaking, you want files to be members of your target when they:

一般来说,您希望文件在以下情况下成为目标的成员:

  • Form part of the executable (e.g. implementation (.m) files or libraries), or
  • Are included as files in the application bundle (e.g. images).
  • 形成可执行文件的一部分(例如实现 ( .m) 文件或库),或
  • 作为文件包含在应用程序包中(例如图像)。

You don't need files to be members of your target if they are only used as part of the build process and aren't needed at runtime. Typically this is any type of header file, including precompiled headers (.pch).

如果文件仅用作构建过程的一部分并且在运行时不需要,则不需要文件成为目标的成员。通常这是任何类型的头文件,包括预编译头文件 ( .pch)。

回答by Mundi

Only .mfiles and resource files are part of the targets, not .h.

只有.m文件和资源文件是目标的一部分,而不是.h.

You are right: the Info.plist files and the headers are all referenced in the build settings (which again are target specific).

你是对的:Info.plist 文件和标题都在构建设置中被引用(这也是特定于目标的)。

回答by Wain

Headers only need to be copied for a framework target, and only because they are part of the framework release (they allow users to know how to use the framework). Apps don't need the headers because they're compiled stand alone entities. The headers (and the pch file) are used during compilation but aren't required at runtime.

仅需要为框架目标复制标头,并且仅因为它们是框架版本的一部分(它们允许用户知道如何使用框架)。应用程序不需要标头,因为它们是编译的独立实体。头文件(和 pch 文件)在编译期间使用,但在运行时不需要。

The info.plist is handled differently. It usually can't just be copied because in the project it usually isn't called "Info.plist". It's also mandatory for the file to exist in the app so Xcode doesn't give you the option of not including it.

info.plist 的处理方式不同。它通常不能被复制,因为在项目中它通常不被称为“Info.plist”。该文件也必须存在于应用程序中,因此 Xcode 不会为您提供不包含它的选项。