Painted levels: being fostered fostered fostered
Tags: “iOS” “CocoaPods” “dependencies library” by MrLiuQ Review: QiShare team
Question: In our daily development, we will inevitably use some third-party libraries (such as AFNetworking, SDWebImage…). And those third party libraries may refer to other third party libraries, so we have to introduce other third party libraries. (Old saying: children and grandchildren are endless)
In addition, if a third-party library is updated, you have to manually reintroduce the new library. (It’s a hassle anyway)
- Need: Is there a tool to help developers manage third-party libraries? When the third-party library is updated, can you update the third-party library in time with some simple commands?
The powerful CocoaPods were born. Today we are going to take a look at CocoaPods and how to install and use it.
CocoaPods
CocoaPods is a library management tool for developing iOS projects. It has more than 55,000 libraries and is used in more than 3 million applications. Using CocoaPods allows you to gracefully extend projects and easily import third-party open source libraries.
Add: CocoaPods official website
2, CocoaPods environment construction:
-
Step 1: You need to install the Ruby environment before installing CocoaPods.
-
Step 2: Use ruby-China’s Ruby mirror source.
$gem sources –remove https://rubygems.org/ $gem sources -a https://gems.ruby-china.com/ To verify that the Ruby image source is ruby-China, use the $gem sources -l command.
- Step 3: Install cocoaPods:
Run sudo gem install cocoapods (if no read/write permission is available, run sudo gem install -n /usr/local/bin cocoapods instead.)
Basic Usage of CocoaPods
The steps are as follows:
1. Use Terminal to locate the project directory and create a Podfile.
Use the command pod init.
2. Open the Podfile.
Use the command: open Podfile.
3. Search for the framework to be imported.
Use the command: pod search framework name.
4. Write the framework information to the Podfile.
Platform :ios,'10.0' target: do pod'AFNetworking','~>3.2.1' pod'SDWebImage'... endCopy the code
About version range:
symbol | meaning |
---|---|
> 0.1 |
Any version later than 0.1 (excluding 0.1) |
> = 0.1 |
Any version later than 0.1, including 0.1 |
< 0.1 |
Any lower than version 0.1 (excluding version 0.1) |
< = 0.1 |
Any version lower than 0.1 inclusive |
~ > 0.1.2 |
Version 0.1.2 to 0.2, excluding 0.2. Equivalent to >= 0.1.2 and <0.2.0, and always the latest version in your specified range. |
Do not specify | The default version is the latest version |
5. Install the third-party framework
Use pod install (PS: if the current network condition is not good, you can not update the index library, directly use pod install –no-repo-update command.)
Four, for example,
Here xiaobian gives an example of importing AFNetworking and SDWebImage framework W.
-
Let’s create a new project: QiCocoaPods.
-
Find the project directory through the terminal and create a new Podfile, as shown below:
-
Use the pod search AFNetworking command
The following interface appears:
- Use the following command:
open podfile
Open the Podfile file. Write frame information, as shown in the figure:
- Install the specified third-party library: use the command
pod install
. The diagram below:
- Open the
.xcworkspace
File, start programming. (.xcworkspace
Instead of a.xcodeproj
)
Fifth, supplementary q&A
- Added a:
pod install
withpod update
The difference between?
A:
Pod Install: Install all the required libraries using pod Install for the first time. In subsequent use, libraries that were not previously introduced are introduced. Pod update: Updates all libraries to the latest version in the specified version range.
- Add 2:
pod install
withpod install --no-repo-update
The difference between?
A:
Pod Install: The local REPo library is updated before installation. Pod install –no-repo-update: install pod directly without updating the local repo library.
Ways to focus on us are:
QiShare(GitHub) QiShare(CocoaChina) QiShare(StackOverflow) QiShare(wechat)
Recommended articles:
IOS Xcode Bitcode iOS drawRect iOS write high quality Objective-C code (eight) strange dance weekly