IOS package dependency management tools

IOS package dependency management tool (part 1) : CocoaPods

IOS package dependency management tool (ii) : CocoaPods principle and knowledge

IOS package dependency management tool (3) : create your own Pod library

IOS Package dependency Management tool (4) : Swift Package Manager (SPM) Introduction

IOS Package dependency Management tool (5) : Swift Package Manager (SPM) Customization

IOS package dependency management tools (6) : CocoaPods VS SPM Summary

One, foreword

1.1. What is CocoaPods?

It is a package dependency management tool for Xcode projects that require third party packages! Maven for Java, JCenter for Android, NPM for Node, and YARN all have the same job responsibilities.

1.2. Is this tool necessary?

Not necessary in theory, but necessary in practice! Especially apple developers (because they all involve Xcode to develop).

1.3 Steps for manual introduction of third-party open source libraries

  1. Copy the open source library source into the project;
  2. Add dependency frameworks and dynamic libraries;
  3. Manual configuration (compile phase, connector options), set ARC environment -objc, -fno-objc-arc and other parameters;
  4. Manage version updates of the library;
  5. If the library also involves other third parties, repeat the above steps.

1.4 purpose of CocoaPods

CocoaPods aims to improve engagement and discoverability of third-party open source Cocoa libraries. These project goals have influenced and driven CocoaPods’ design:

  • Create and share libraries and use them in projects without creating additional work for library authors;
  • Integrate non-Cocoapods libraries and hack on your own branch of any CocoaPods library using the simple transparent Podspec standard;
  • Allow library authors to build libraries as they like;
  • Save library authors time by automating a lot of Xcode work unrelated to their library functionality;
  • Support for any source code management tool (currently supported git, SVN, Mercurial, Bazaar, and various types available via HTTP);
  • Promotes a culture of distributed collaboration on PODS, but also provides capabilities that can only be nurtured through centralized solutions;
  • Build tools on top of core Cocoa development systems, including tools that are typically deployed to other operating systems, such as Web services;
  • Provide purposeful and automatic integration, but make it completely optional, so you can manually integrate CocoaPods dependencies into Xcode projects as needed, with or without workspaces;
  • Solve daily problems for Cocoa and Xcode developers;

1.5. Benefits of CocoaPods

  • The tool is open source and available on GitHub;
  • Through the CocoaPods configuration file, you can easily import the required third-party open source libraries.
  • Third party library version management is simple, easy to upgrade;
  • Easy to find third-party libraries (official website or command line);
  • A typical project is a team effort, and team members can install the tool to complete the introduction of third-party libraries (no need for everyone to do step 1.3);
  • Make a public library and publish it to CocoaPods so that others can use it easily.

Install CocoaPods

CocoaPods is developed by Ruby, so installing on macOS requires Ruby.

Before installing the following tools, ensure that both xcode and xcode-select are installed.

  • Xcode can be updated via the App Store;
  • Xcode-select you can run the following command: $xcode-select –install

2.1, HomeBrew

Homebrew is a software package management tool based on the Mac OS platform. It has many practical functions such as installation, uninstallation, update, view, search and so on. Package management can be implemented with a simple command, and you don’t have to worry about dependencies and file paths. It is very convenient and quick. So we need to download Homebrew to install Ruby.

  • Install HomeBrew
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Copy the code
  • Uninstall the HomeBrew
$ cd `brew --prefix`
$ rm -rf Cellar
$ brew prune
$ rm `git ls-files`
$ rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
$ rm -rf .git
$ rm -rf ~/Library/Caches/Homebrew
Copy the code
  • HomeBrew use

Check the Homebrew command: brew help

Install any package: brew install // eg: brew install node

Uninstall any package: brew uninstall // eg: brew uninstall git

Query the available package: Brew Search

Query the brew List of installed packages

View any package information: Brew Info

Homebrew: Brew update

Homebrew Help information: BREW-h

View the BREW version: BREW-V

Update brew version: Brew Update

ZSHRC -e, open ~/.bash_profile-e

2.2. Install Ruby

MacOS comes with Ruby, though it may be in a lower version.

$sudo brew install Ruby // Updating Ruby to the latest is highly recommendedCopy the code

Once installed, you have RubyGems, Ruby’s Sophisticated Package Manager. Ruby has another tool: RVM (Ruby Version Manager).

$gem source -l *** CURRENT SOURCES *** https://rubygems.org/ https://rubygems.org/ // Add new source (domestic Ruby image) $gem source -a https://gems.ruby-china.com/Copy the code

2.3. Install CocoaPods

$sudo gem install Cocoapods =====> ERROR: While executing gem... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory. Use the following command instead: Sudo gem install -n /usr/local/bin cocoapods) $pod setup // Sometimes there are problems with installing the cocoapods ~/. Cocoapods /repos might not be generated, so we have to do it manually:  $ mkdir -p ~/.cocoapods/repos $ cd ~/.cocoapods/repos $ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git $ pod setupCopy the code

Create a Pod project

3.1 Searching for the third-party package “AFNetworking”

$pod Search AFNetworking -> AFNetworking (4.0.1) A delightful Networking Framework for Apple Ffices.pod 'AFNetworking', '~ > 4.0.1' - Homepage: https://github.com/AFNetworking/AFNetworking - the Source: https://github.com/AFNetworking/AFNetworking.git - Versions: 4.0.1, 4.0.0 3.2.1, 3.2.0, 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0 - beta. 3, 3.0.0 - beta. 2, 3.0.0 - beta. 1, 2.7.0, 2.6.3 2.6.2, 2.6.1, server, 2.5.4 2.5.3, 2.5.2, 2.5.1, 2.5.0, against 2.4.1, 2.4.0, 2.3.1, 2.3.0 and 2.2.4, 2.2.2, 2.2.3, 2.2.1, 2.2.0, 2.1.0 2.0.3 2.0.2, 2.0.1, 2.0.0, 2.0.0 -rc3, 2.0.0 - RC2, 2.0.0 RC1, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0 RC3, 1.0 RC2, 1.0 RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [Trunk Repo] - Subspecs: - AFNetworking/Serialization (4.0.1) - AFNetworking/Security (4.0.1) - AFNetworking/Reachability (4.0.1) - AFNetworking/NSURLSession (4.0.1) - AFNetworking/UIKit (4.0.1) - > other version: / / control + z exitCopy the code

3.2. Create project and Pod files

// Create Podfile $touch Podfile in demo root directoryCopy the code

3.3 configuring third-party Libraries (PodFiles)

# Define a global platform for your project platform :ios, '9.0' official source warehouse address # 'https://github.com/CocoaPods/Specs.git' target 'demo' do # # the first four Spaces can specify a version number pod 'AFNetworking', '~> 4.0.1' # default to use the latest version pod 'AFNetworking' endCopy the code

3.4. Install third-party libraries

View the pre-installation directory structure

$ ls -l total 8 -rw-r--r-- 1 chris staff 312 12 7 16:04 Podfile drwxr-xr-x 9 chris staff 288 12 7 16:08 demo drwxr-xr-x@  5 chris staff 160 12 7 16:08 demo.xcodeprojCopy the code
  • Install third-party dependency packages
$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (4.0.0)
Generating Pods project
Integrating client project

 [!] Please close any current Xcode sessions and use `demo.xcworkspace` for this 
 project from now on. Pod installation complete! There is 1 dependency from the 
Podfile and 1 total pod installed.
Copy the code
  • View the directory structure after installation
$ ls -l
total 16
-rw-r--r--  1 chris  staff  312 12  7 16:04 Podfile
-rw-r--r--  1 chris  staff  798 12  7 16:11 Podfile.lock
drwxr-xr-x  8 chris  staff  256 12  7 16:11 Pods
drwxr-xr-x  9 chris  staff  288 12  7 16:08 demo
drwxr-xr-x@ 5 chris  staff  160 12  7 16:11 demo.xcodeproj
drwxr-xr-x  3 chris  staff   96 12  7 16:11 demo.xcworkspace
Copy the code

  • Double-click “Demo.xcworkspace” to see projects managed by Pod