I have a project for a cocoapod (let's call it "Main") which has a dependency with another cocoapod (let's call this one "Util").
I can add the Util in Main's Podfile via "pod 'Util'" and specify it as a dependency in the podspec via "s.dependency 'Util'"
As long as at least one of these are written, my test project for the pod runs fine (altho without the dependency in the podspec, running the "pod lib lint" command returns errors)
Specifying the pod in the Podfile allows me a lot more granularity as to how precise I want the version to be, even allowing me to use :head as a target. However, the dependency seems much more limited, requiring tags.
I would like to know the difference between these two approaches and if there are good practices to use when one pod depends on another (especially since I'd want to use Main as a pod for other projects eventually)
You could say Podfile is your project configuration, and Podspec is your library configuration.
A Podspec, or Spec, describes a version of a Pod library. One Pod, over the course of time, will have many Specs. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.
The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects. The file should simply be named Podfile . All the examples in the guides are based on CocoaPods version 1.0 and onwards. If you want multiple targets to share the same pods, use an abstract_target .
You could say Podfile is your project configuration, and Podspec is your library configuration.
Podfile
pod 'library_name'
) need to have a Podfile. This is where that information goes.Library_name.podspec
, which is formatted with Ruby DSL syntaxpod 'library_name'
). When you pod trunk push
, you are pushing the JSON version of this file, e.g. LibName.podpsec.json
, for example, here.In your case, you just have code which you're not sharing with anyone. Therefore, it doesn't need to be a library, you can just have everything in your Podfile as a separate target, and you don't even need a Podspec. If you want to share the library with others via Cocoapods, then you need the Podspec file. But, if you want to re-use main across different projects, then the configuration you want to share with those projects should be in the .podspec
file, and you can reference the local directory containing the podspec in your other repos.
More information about Podspec in the documentation.
A specification describes a version of Pod library. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.
I would suggest you release your package/ library through Swift Package Manager instead of Cocoapods or Carthage. All the benefits of Cocoapods can be achieved with SPM. Users can easily migrate to using Swift Packages in their Xcode project because it is built-in, so there is no need to support other package managers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With