Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CocoaPods and Carthage

I had a project with both Carthage and Cocoapods. They both have one common dependency (PureLayout, to be precise). Strange, but project compiles fine without any errors about class redeclaration, etc. So the question is: why it works and which version of dependency is actually used when I call PureLayout's methods – Carthage's or Cocoapods' one?

like image 229
Alexander Doloz Avatar asked Jun 10 '16 09:06

Alexander Doloz


People also ask

What is CocoaPods and Carthage?

Carthage and CocoaPods are very different in terms of building the dependencies and integrating them in the project. CocoaPods is centralized dependency manager and it will build your dependencies and integrate them directly in the project by creating new . xcworkspace workspace.

What is iOS Carthage?

Carthage is a simple dependency manager for macOS and iOS, created by a group of developers from GitHub. Not only was Carthage the first dependency manager to work with Swift, but it's also written in Swift! It exclusively uses dynamic frameworks, rather than static libraries.

What is CocoaPods used for?

Cocoapods is an application level dependency manager that runs on objective-c, swift, and any other programming languages that run on Objective-C. It focuses on source-based distribution of third party code and allows automatic integration to your Xcode projects.


2 Answers

Carthage and CocoaPods are very different in terms of building the dependencies and integrating them in the project.

CocoaPods is centralized dependency manager and it will build your dependencies and integrate them directly in the project by creating new .xcworkspace workspace. This means that you get access to the build dependencies right after building.

Carthage on the other hand is decentralized dependency manager and it leaves you with the task of integrating the dependencies into your project. Carthage builds the frameworks specified in Cartfile and moves them to Carthage/Builds folder. After the build process it's up to you to integrate and manage the dependencies.

In your case, when you build your PureLayout dependency with CocoaPods and Carthage, CocoaPods integrated it to project and Carthage left you with builds in Carthage/Builds which means that you used only CocoaPods build version of PureLayout.

Also, it's a bad practice to use multiple package/dependency managers. You should stick to the one and be comfortable with it.

like image 97
Said Sikira Avatar answered Oct 03 '22 17:10

Said Sikira


iOS Dependency manager

When you do not use a Dependency manager as a developer you are responsible for:

  • finding a dependency
  • resolving a dependency graph and versioning
  • downloading the sources
  • add the dependency into Xcode

And when you decide to upgrade the dependency you should start this process from the beginning

Dependency manager is a tool that helps user to add a dependency into a project with a minimum affords

CocoaPods[About] is an open-source, centralised dependency manager for Swift and Objective-C Cocoa projects which is being written on Ruby. It Supports Dynamic Frameworks and Static Libraries[timeline]

Notes:

  • CocoaPods needs to have a workspace

  • A consumer project does not have a clean view of dependencies <Pods_target-name.framework>

  • All dependencies are rebuild every time when you build the project.

  • It is not possible to use different pod versions in the same workspace

    CocoaPods could not find compatible versions for pod
    

Carthage[About] is an open-source, decentralised dependency manager for Swift and Objective-C Cocoa projects which is being written on Swift. It supports Dynamic Frameworks and Static Libraries

Notes:

  • As a consumer project developer you are responsible for setup Xcode with a dependency. It creates some extra steps in IDE
  • As a dependency developer you do not have some instruments(e.g. subspecs)

Swift Package Manager(SPM)[About] is an open-source, decentralised dependency manager which is being written on Swift. It supports Dynamic and Static library. .xcodeproj is not used. If you want to distribute closed-source(binary framework) you should use XCFramework[About]

*CocoaPods by default builds open-source pods every time(after clean or any unknown reason) which increase build time(but you can use cocoapods-binary), Carthage and SPM pre-builds framework by default.

*closed-source allows you to close the source code and save build time, but can have issues with ABI stability[About]

like image 32
yoAlex5 Avatar answered Oct 03 '22 15:10

yoAlex5