CocoaPods has been around for years and I’m sure many students will use it, but do you really know how it works?

RubyGems

The RubyGems software allows you to easily download, install, and use ruby software packages on your system. The software package is called a “gem” which contains a packaged Ruby application or library.

People, especially computer engineers, often think of machines. They said, “If you do this, the machine will run faster; In this way, the machine runs more efficiently; Do that, and the machine will do that.” In fact, we need to think in terms of people, how people write programs or use applications on machines. We are the masters, they are the servants ———— Ruby was designed to be

CocoaPods is an iOS package management tool written in Ruby, while RubyGems is a Ruby package management tool. Installing CocoaPods requires the package management tool RubyGems, which comes with the Mac. For more information about RubyGems, see the official documentation. However, Gems in RubyGems are slow to access domestically, but Ruby China is available. If you want to learn about Ruby in general, check out this article Ruby. Now that you’ve read this, you know a little bit about installing CocoaPods.

CocoaPods will be installed to/Users/wangsuyan /. CocoaPods/repos

Git

To master CocoaPods, you’ll need to know some basics about Git, and you’ll need to have at least one code-hosting platform, such as GitHub. Of course this article is very good. The following is mainly related to this article.

  • Git add-a commits the text to the staging area and waits for the commit

  • Git commit -m “Commit info” commit code to HEAD. Now, your changes are committed to HEAD, but not to your remote repository

  • Git tag 1.0 tags the current version to commit

  • Git push — Tags commit all tags to the remote repository

Pod init

It first needs to determine whether the current directory has XCODEPROJ project, if there is no direct error; If there is a single XCODEPROJ project, a podfile is created directly. If there are multiple XCODEPROJ projects, you need to specify a project, otherwise an error will be reported:

[!] Multiple Xcode projects found, please specify one

Podfile

A Podfile is generated after Pod init. It is a specification that describes the dependencies of one or more Xcode projects (targets).

The simplest Podfile, which simply adds a SDWebImage library to Target lefeKit.

Platform :ios, '9.0' target 'lefeKit' do pod 'SDWebImage' endCopy the code
  • use_frameworks!

Required when using Swift or dynamic libraries

  • Version, such as:Pod 'SDWebImage', '~ > 3.7.0'

Suppose SDWebImage currently only has the following versions:

4.1.0, 4.0.0 4.0.0 - beta 2, 4.0.0 - beta, 3.8.2, 3.8.1, 3.8.0, 3.7.6, 3.7.5, 3.7.4, 3.7.3, 3.7.2, 3.7.1, 3.7.0, 3.6, 3.5.4, 3.5.2 3.5.1 track of, 3.5, 3.4, 3.3, 3.2, 3.1, 3.0, 2.7.4, 2.7, 2.6, 2.5, 2.4Copy the code

So pod ‘SDWebImage’, ‘~> 3.7.0’ will only install version 3.7.6, the last one. The highest version of;

Pod ‘SDWebImage’, ‘> 3.7.0’ installed greater than version 3.7.0, of course there are >=, <= and <

Pod ‘SDWebImage’, ‘3.7.6’ specifies version 3.7.6

  • :pathSpecify the local Pod library

pod 'FLoatDemo', :path => '~/Desktop/TestDemo/FLoatDemo'

This address is not a random directory can be, must be a Pod library, otherwise will report an error

No podspec found for `FLoatDemo` in `~/Desktop/TestDemo/FLoatDemo`
Copy the code
  • Specify the source

If a third-party library does not meet the needs of your project, you can Fork it and modify the third-party code.

pod 'SDWebImage', :git => 'https://github.com/lefex/SDWebImage.git', :commit => '94cdb773d74967f7ba2feecf0d151012bd965fde'
Copy the code

You can also have: :branch, :tag => ‘3.1.1’

  • Subspecs

A library may be large, but you only need a certain part. You only need to import the part you need, for example:





SDWebimage.png

How about pod ‘SDWebImage /Core ‘only: pod ‘SDWebImage’, :subspecs => [‘Core’, ‘GIF’]

  • Remove the warning

Remove all warnings inhibit_all_warnings!

Remove a library warning pod ‘SDWebImage’, ‘~> 4.1.0’, : Inhibit_warnings => true

pod install

If you have modified the Podfile, execute Pod Install. When pod Install is executed, the dependent libraries are installed as described in the Podfile. This generates a lot of files.

  • Podfile.lock

This file is mainly used to lock the version of the Pods library. Ensure that the tripartite libraries used by members of the group are the same version. If not handled properly, there could be a serious conflict here.

  • Manifest.lock

Lock is a copy of Podfile.lock, which generates the same manifest. lock every time podfile. lock is generated and stored in the Pods folder. At each project Build, a script is run to check whether podfile. lock and manifest. lock are consistent, and if they are inconsistent, an exception is thrown. This is the script for it.

diff "${PODS_PODFILE_DIR_PATH}/Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null
if [ $? != 0 ] ; then
    # print error to STDERR
    echo "error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation." >&2
    exit 1
fi
# This output is used by Xcode 'outputs' to avoid re-running this script phase.
echo "SUCCESS" > "${SCRIPT_OUTPUT_FILE_0}"
Copy the code

pod update

You only need to update your Pods to the new version. For example, the current version of SDWebImage in the lefeKit project is 3.7.0. Pod ‘SDWebImage’, ‘>3.6.0’, after executing pod install, the local SDWebImage version will still be 3.7.0. It changes to 4.1.0 after pod update

Publish a Pod library

create

The following uses lefeKit as an example to illustrate the process of creating a private library.

  • Pod lib create lefeKit At this time, you need to enter a prompt question, according to the official document step by step to complete;
  • Log on to Github and create a new one calledlefeKitThe project;
  • Modify thelefeKit.podspecFile,

    s.source = { :git => 'https://github.com/lefex/lefeKit.git', :tag => s.version.to_s }It should be the address of the project you created on Github;s.homepage = 'https://github.com/lefex/lefeKit'
  • Create a directory in the root directory (lefeKit)Classes
  • pod lib lintchecklefeKit.podspecIf there is any error in the file, success will be displayedlefeKit passed validation;
  • After everything is in order, executepod trunk push lefeKit.podspec
  • pod trunk meYou can view my registration information

Not all of these steps are in sequence. The key to creating a private library is to create an XXx. podspec file and a Repository to associate with the Repository.

The prompt for successful release is as follows:

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 🎉 Congrats 🚀 lefeKit (1.0.0) Successfully published 📅 August 28 th, 21:58 🌎 https://cocoapods.org/pods/lefeKit 👍 Tell your friends! --------------------------------------------------------------------------------Copy the code

Updating a private library

  • Modify thelefeKit.podspecThe version number in the file;
  • Tag tat 1.0.0, add a tag;
  • git push –tags
  • pod lib lint
  • pod trunk push lefeKit.podspec

Error summary

Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.
Copy the code

If you encounter this error, you have not registered your account. Register a pod Trunk register [email protected]

WARN  | url: The URL (https://github.com/lefex1/lefeKit) is not reachable
Copy the code

To ensure correct address can visit https://github.com/lefex1/lefeKit for https://github.com/lefex1/lefeKit

ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
Copy the code

Unable to find the resource file, create the Classes folder in the root directory and create the file. s.source_files = ‘lefeKit/Classes/**/*’

Unable to find a pod with name, author, summary, or description matching `lefeKit`
Copy the code

This is the problem that the local cache: clear the cache the rm – rf ~ / Library/Caches/Cocoapods, perform pod setup

skills

Add –verbose after all commands to display more debugging information.

Recommended reading

【iOS internationalization 】 how to reduce the workload of internationalization from 3 days to 10 minutes

Thank you

About the podfile. lock pain

BY Blog

pluto-y

Cocoapods

Ruby China