xcode 继承什么!:search_paths 吗?

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

What does inherit! :search_paths do?

iosxcodecocoapods

提问by Quentin

After looking at CocoaPods' own example (from https://guides.cocoapods.org/syntax/podfile.html#abstract_target)

查看 CocoaPods 自己的示例后(来自https://guides.cocoapods.org/syntax/podfile.html#abstract_target

# Note: There are no targets called "Shows" in any of this workspace's Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'

  # The target ShowsiOS has its own copy of ShowsKit (inherited) + ShowWebAuth (added here)
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # The target ShowsTV has its own copy of ShowsKit (inherited) + ShowTVAuth (added here)
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Our tests target has its own copy of
  # our testing frameworks, and has access
  # to ShowsKit as well because it is
  # a child of the abstract target 'Shows'

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

I don't see why inherit! :search_pathsis necessary? All 3 targets, ShowsiOS, ShowsTVand ShowsTestshave access to ShowsKitfrom their parent target.

我不明白为什么inherit! :search_paths有必要?所有 3 个目标、ShowsiOSShowsTVShowsTests都可以ShowsKit从其父目标访问。

The specific example for inherit!(from https://guides.cocoapods.org/syntax/podfile.html#inherit_bang) doesn't add any clarity

inherit!(来自https://guides.cocoapods.org/syntax/podfile.html#inherit_bang)的具体示例没有增加任何清晰度

target 'App' do
  target 'AppTests' do
    inherit! :search_paths
  end
end

Can you help me understand what inherit! :search_pathsis for?

你能帮我理解是什么inherit! :search_paths吗?

回答by Christopher Reyes

The purpose behind behind inherit!, according to https://guides.cocoapods.org/syntax/podfile.html#inherit_bang(which I would agree is not very clear), is to provide one of 3 available modes:

inherit!根据https://guides.cocoapods.org/syntax/podfile.html#inherit_bang(我同意不是很清楚),背后的目的是提供 3 种可用模式之一:

  • :completeThe target inherits all behaviour from the parent.
  • :noneThe target inherits none of the behaviour from the parent.
  • :search_pathsThe target inherits the search paths of the parent only.
  • :complete目标从父级继承所有行为。
  • :none目标没有继承父级的任何行为。
  • :search_paths目标仅继承父级的搜索路径。

In this question's example it is the :search_pathsmode that is being expressed. The three different modes serve different roles when testing a Pod project.

在这个问题的例子中,它:search_paths是被表达的模式。在测试 Pod 项目时,这三种不同的模式扮演着不同的角色。

Here is an additional linkpertaining to Framework Search Paths in Xcode that helped clear some confusion for me.

这是一个与 Xcode 中的框架搜索路径有关的附加链接,它帮助我消除了一些困惑。

回答by yoAlex5

A target with a dependency can use this functionality. The best example is Test targetthat uses app target. In this case you can create a hierarchy in your Podfile[About]

具有依赖性的目标可以使用此功能。最好的例子是Test target使用app target. 在这种情况下,您可以在[关于] 中创建层次结构Podfile

target 'App' do
  target 'Tests' do
#    inherit! :none            # empty
#    inherit! :complete        # by default if you do not specify any inherit!
#    inherit! :search_paths    # uses only `search` paths 
  end
end

Take a look at generated Pods/Targets Support Files/directory and compare

查看生成的Pods/Targets Support Files/目录并进行比较

Pods-<App_target_name>/Pods-<App_target_name>.<debug/release>.xcconfig
Pods-<Test_target_name>/Pods-<Test_target_name>.<debug/release>.xcconfig

You will find that settings which are passed to to the project's target[About]are different for different inherit!setting.

您会发现传递给项目目标[About]inherit!设置对于不同的设置是不同的。

In case with inherit! :search_paths- FRAMEWORK_SEARCH_PATHS, HEADER_SEARCH_PATHS... were inherited and were passed to the corresponding fields in Build Settings

如果inherit! :search_paths- FRAMEWORK_SEARCH_PATHS, HEADER_SEARCH_PATHS... 被继承并被传递到相应的字段Build Settings

Use case of inherit! :complete. When you develop a framework that has a third-party dynamic framework and you have a test target. If you do not do this and run tests you will get dyld: Library not loaded[About]

的用例inherit! :complete。当您开发具有第三方动态框架的框架并且您有测试目标时。如果您不这样做并运行测试,您将获得dyld: Library not loaded[关于]