What does inherit! :search_paths do?

IosXcodeCocoapods

Ios Problem Overview


After looking at CocoaPods' own example (from 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_paths is necessary? All 3 targets, ShowsiOS, ShowsTV and ShowsTests have access to ShowsKit from their parent target.

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

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

Can you help me understand what inherit! :search_paths is for?

Ios Solutions


Solution 1 - Ios

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:

  • :complete The target inherits all behaviour from the parent.
  • :none The target inherits none of the behaviour from the parent.
  • :search_paths The target inherits the search paths of the parent only.

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

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

Solution 2 - Ios

CocaPods and inherit!

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

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-<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.

In case with inherit! :search_paths - FRAMEWORK_SEARCH_PATHS, HEADER_SEARCH_PATHS... of inner target were inherited from outer target and were passed to the corresponding fields in 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]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionQuentinView Question on Stackoverflow
Solution 1 - IosChristopher ReyesView Answer on Stackoverflow
Solution 2 - IosyoAlex5View Answer on Stackoverflow