In the process of iOS development, we always inevitably use some third-party frameworks, such as AFNetworking, SDWebImage, MJRefresh, etc. The author used to download zip compressed files of third-party frameworks directly on GitHub. Then you drag the framework into your own project and use it, which is cumbersome to handle each time. I’ve been using CocoaPods to gracefully manage third-party frameworks, so I’m going to share with you how to use it

  • Open the terminal, the operations in this article are carried out on the terminal

  • Upgrade Gem to latest version (sudo keyword is administrator permission, need to enter password)

sudo gem update --systemCopy the code

Gem is the standard package for managing Ruby libraries and programs. It uses Ruby Gem sources to find, install, upgrade, and uninstall packages. MacOS itself supports the Ruby environment

sudo gem install cocoapodsCopy the code

Note 1: If you are a mainland user, the installation may fail in this step, because the default source Gem looks for is rubygems.org/, mainland users can choose to use VPN to bypass the wall to complete the installation, or change the source to a mainland accessible address ruby.taobao.org/

Caution 2: If the source code header is HTTPS, Error response Not Found 404 will fetch when you reference this code

1. Remove the default gem sources --remove https://rubygems.org/ 2. Add alternative source gem sources -a https://ruby.taobao.org/ 3. Check the Gem source Gem source-l. 4. Install CocoaPods againCopy the code
  • Initialize CocoaPods and update third-party framework information locally
pod setupCopy the code
  • You can run the following command to update third-party framework information to the local PC
pod repo updateCopy the code
  • Change the REPO address (this step is only for users who failed to update third-party frameworks)
1. Remove default pod repo remove master 2. Add alternative pod repo add master 3 at https://gitcafe.com/akuandev/Specs.git. Try updating third-party framework information againCopy the code
  • If you search for third-party frameworks (AFNetworking for example), CocoaPods can only manage third-party frameworks that you can find
pod search AFNetworkingCopy the code
  • Use CocoaPods to add AFNetworking to the Demo project placed on your desktop
1. Locate a path to the root directory of the Demo project CD/Users/liupeng/Desktop/Demo 2. Create the file Podfile to write to the desired frame vim Podfile 3. Type I for editing. The first line is' platform :ios' and the next line is' pod 'AFNetworking', '~> 3.0.4' 4. Press ESC to exit the editing mode and enter :wq to save the configuration and exit. 5. Install pod InstallCopy the code

Note 1: Podfile files can be edited manually, even without a terminal

Note 2: After the third-party framework is installed successfully, a workspace with the suffix xcworkspace will appear in the project root directory. Xcworkspace will be used to open the project in the future instead of xcodeProj

Note 3: Instead of using #import “”, use #import <> when introducing third-party frameworks into your project.

  • Upgrade or uninstall third-party frameworks (AFNetworking as an example)
1. Locate a path to the root directory of the Demo project CD/Users/liupeng/Desktop/Demo 2. Create the file Podfile to write to the desired frame vim Podfile 3. Enter I to edit pod 'AFNetworking' and delete the line '~> 3.0.4' to uninstall it. If you do not write the version number, the latest version will be downloaded by default. Press ESC to exit the editing mode and enter :wq to save the configuration and exit. 5. Install pod InstallCopy the code