Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

Abstract

Third party library is very likely to be used in the project. It is highly efficient to introduce the third party library through Pod. Here we introduce a new project to build a Pod environment, which is convenient to introduce the third party library files into the project.

If the third party library is needed in the newly created project, the common way is to add it through Pod to facilitate the update of the third party library. Another option is to download the source file from a third-party library and add the entire file to the project. Here mainly describes the common methods, processing process, and possible problems.

First create an empty project through Xcode, then open the terminal, enter the command to switch to the project directory, the home directory is ls command, then see.xcodeProj file, that is the home directory:

➜  ~ cd /Users/songhang/Desktop/NewProduct 
➜  NewProduct ls
NewProduct           NewProductTests
NewProduct.xcodeproj NewProductUITests
➜  NewProduct 
Copy the code

To create the Podfile, continue typing the instruction POD init in the terminal:

➜  NewProduct pod init
Copy the code

A Podfile is automatically generated in the project’s home directory, which you can double-click to open (if you have a text editor, whichever you have). Then add any third-party libraries you need to this file

The source 'https://github.com/CocoaPods/Specs.git' platform: ios, '10.0' use_frameworks! target 'NewProduct' do pod 'Alamofire' pod 'SwiftyJSON' pod 'Kingfisher' pod 'MJRefresh' pod 'KakaJSON' pod 'IQKeyboardManagerSwift' pod 'WechatOpenSDK' pod 'GoogleSignIn' endCopy the code

Note the source ‘https://github.com/CocoaPods/Specs.git’ is not in a newly created file, need to manually add, holds the NewProduct, is the name of the project, here is my project name, you have to fill in your project.

Then save it and continue typing pod install on terminal:

➜  NewProduct pod install
Copy the code

Then it is waiting for the terminal to pull the remote third-party library file, if the network speed is not good, the waiting time is relatively long.

In addition to the Pods folder, an.xcworkspace file will be generated in the project’s home directory. Then you need to click on it to enter the project.

But when a third-party cull fails, you’ll only see the Pods folder, not the XCWorkspace project file.

So if you want to avoid generating an XCWorkspace file because one of the third-party libraries failed to pull, hide the pod libraries for the time being, i.e

The source 'https://github.com/CocoaPods/Specs.git' platform: ios, '10.0' use_frameworks! target 'NewProduct' do endCopy the code

If you re-pod install on the terminal, you should see xcWorkspace generated in your home directory and open your project with it. Then add the third-party libraries one by one and run Pod Install to update the Pods folder.

There are different reasons for the failure of pulling third-party libraries, such as network speed and library loss, etc. This can be handled according to the error information reported in the terminal.

At this point, the process of introducing third-party libraries is complete and you can proceed to the next steps.

digression

Time is short and what you said may not be comprehensive. If you encounter any problems during your review, please leave a message in the comment section and I will reply as soon as possible.