iosxcodecocoapodspod-installxcode-build-phase

How does CocoaPods add files to a target when they're actually not added as a member of a target?


I'm working with a CocoaPod private library. We have mock files that are being used for our Swift Previews.

What's surprising is that these mock files aren't added as a member to the pod's target. They're a a member of the Test Target. Yet they compile.

I don't understand why/how it's working


Solution

  • When I further inspected the setup I noticed that within the PodSpec, for its source_files field I saw something like the following:

     # mock files are being built into the pod so they can be used for SwiftUI previews
     s.source_files = 'OurCoolPod/**/*.{swift,storyboard}', 'Example/Tests/Mocks/**/*.swift', 'Example/Tests/ManagerMocks/*Mock*.swift', 'Example/Tests/HelpersTestsAndMocks/*Mock*.swift', 
    

    I believe the source files are added onto the target if either:

    Tldr the PodSpec will supercede your Xcode configurations because pod install overrides things.

    But why is CocoaPods like this?

    I suppose mainly because it wants to have a higher focus on the Swift/Objective-C language and less focus on Xcode.

    When you rely on paths instead of a very specific Xcode project file, then other tools like the terminal, vim, VSC can be used a lot easier.

    Like you don't need Xcode running (you need the Xcode Command Line Tools installed though) to execute pod lib lint. And this in itself is a great advantage. It simplifies the development process.