Install and use Cocoapods in iOS Projects
1. First, open our terminal:
2. Enter this command in the terminal: gem sources-l
2.1 If the display is the same as that of me, the image has been added and does not need to be changed. If it is different, you need to change it.
If the output is https://rubygems.org/image,
We want to delete this image, and then add the image: https://ruby.taobao.org/ command as follows:
<1> delete original image: gem sources -- remove https://rubygems.org/
<2> Add a new image: gem sources-a https://ruby.taobao.org/
<3> check whether the image is changed successfully: Enter the following command again, as shown in Figure 2. The image is changed successfully.
3. Next, we will take an important step to install cocoapods...
Input: sudo gem install-n/usr/local/bincoapods
In about 10 minutes, the installation will be successful.
3.1 check whether the installation is successful input: pod search AFNetworking
If shown, the installation is successful.
4. Next we will use cocoapods
4.1 first, create a project. After the project is created, find the project folder in the Finder if you know the path and cd to your project, drag directly into the terminal to run
(Cd-> project file root directory)
4.2 The above is the root directory of my project (remember to go to the root directory of the project), and then we will create a Podfile here,
Command: touch Podfile
As shown in: Podfile is created successfully.
4.3 Next we will operate on the Podfile. There are two ways to write our Podfile.
First, use vim
Second, open Podfile directly to write what we need (and then perform other operations)
4.3.1 First vim operation
For example, if we want to add a third-party library AFNetworking, run the following command: pod search AFNetworking.
Command: pod search AFNetworking is obviously a library for searching AFNetworking requests from a third-party network.
If you want to add that library, you can print the file name of the pod search *** library on the terminal and then display all versions of the library, it is all AFNetworking versions I printed. What I drew in red is what we want to write into our Podflie file.
4.3.1.1 let's use the Vim editor. The terminal prints vim Podfile, as shown in:
Parameters written in: platform: ios, '7. 0' (Note: This parameter indicates the lowest supported System Version)
The second parameter is the content we searched in the previous step. Copy it here and it will be OK.
(Note: we have added what we need and the write is complete. Then we want to save and exit. How can we exit vim here ?, After writing, click the esc button in the upper left corner, enter the colon (: Colon in English), enter wq, (wq means save and exit), and press Enter ):
Enter pod install in the terminal. cocoapods is installed successfully.
4.3.1.2 here we will introduce the second method. We will directly use the Podfile file in our project to write the above content (Note: This method is simple and crude. We recommend that you use this method ):
Open the folder of our project, double-click the Podflie file, and write the above two lines in it:
(I added two third-party libraries) The write is complete. Save commond + s and exit. We will return to the terminal.
Back to the terminal, the next step is the same. We need to import the third-party library AFNetworking in our project.
The following two commands are frequently used.
Note:
[Pod install: Use: pod install -- verbose -- no-repo-update]
[Pod update: Use: pod update -- verbose -- no-repo-update]
4.4 run the following command on the terminal: pod install -- verbose -- no-repo-update
If you see the following words, it indicates that we have successfully imported the Third-Party Library :(:)
Here, we will open the project again and use the single-choice and multiple-choice buttons. xcworkspae to open it.
5. Open our project and you will find that there are more things ,:
So when we open a project again, we need to open the project with the suffix xcworkspace.
6. According to the above directory, we can see that the library we added to AFNetworking has been successfully added, and it is basically completed here.
7. If we do not want this third-party library, how can we delete it ??
If I don't want to add this AFNetworking library now and I want to remove it from our project, what should I do:
You can directly Delete the pod 'afnetworking', '~> 3.0.4'
Next, return to the terminal and enter the command: pod update -- verbose -- no-repo-update (Note: update command)
Then let's look at our Podfile file, which has no AFN library.
Cocoapods is basically like this. Download a third-party library for management and delete the third-party library updates.
Cocoapods Common commands:
Pod install -- verbose -- no-repo-update insert to a third-party library
Pod update -- verbose -- no-repo-update: update a third-party library
Pod install updates all third-party Libraries
Remember to update each time before inserting ^ @ ^ Big_Xin