什么是 Xcode 4 中的目标成员资格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8306003/
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-14 22:35:16  来源:igfitidea点击:

What is target membership in Xcode 4

xcodexcode4

提问by Codier

I am searching for an example for target membership in Xcode. I am a bit confused about what it means exactly. For example, I have two different target membership. myApp and myAppTests. What does it mean if I specify a file (say myAppFile.h) to be part of myAppTests but not myApp? What happens exactly when my app build and run?

我正在寻找 Xcode 中目标成员资格的示例。我对它的确切含义感到有些困惑。例如,我有两个不同的目标成员资格。myApp 和 myAppTests。如果我指定一个文件(比如 myAppFile.h)作为 myAppTests 的一部分而不是 myApp,这意味着什么?当我的应用程序构建和运行时到底会发生什么?

Thanks

谢谢

回答by Mark Szymczyk

Generally header files are not members of targets. Making an implementation file a member of a target tells Xcode to compile the file when you build the target. In your example Xcode compiles the file myAppFile.m when you build the myAppTests target but not when you build the myApp target.

通常头文件不是目标的成员。使实现文件成为目标的成员会告诉 Xcode 在构建目标时编译该文件。在您的示例中,Xcode 会在您构建 myAppTests 目标时编译文件 myAppFile.m,但不会在构建 myApp 目标时编译。

When you have an application target and a unit testing target, your application's implementation files should be members of the application target. Your unit testing classes' implementation files should be members of the unit testing target.

当您有一个应用程序目标和一个单元测试目标时,您的应用程序的实现文件应该是应用程序目标的成员。您的单元测试类的实现文件应该是单元测试目标的成员。

回答by yoAlex5

For example when you create a library or framework you should create a .modulemapwhich includes umbrella header. Every imported header in umbrella should has a publictarget membership

例如,当您创建一个库或框架时,您应该创建一个.modulemap包含伞头的文件。伞中的每个导入的标题都应该有一个public目标成员资格

You can setup a visibility via

您可以通过设置可见性

`Target Membership` in the `Inspector` tab 
//or
Project Settings -> Target -> Build Phases
    .h -> Headers
    .m -> Compile Sources
    .h or umbrella.h and .modulemap -> Copy Files

Read more here

在这里阅读更多