CocoaPods encounters installation, usage, and problems
What is CocoaPods?
Many third-party open-source libraries, such as JSONKit and AFNetWorking, are frequently used when you develop iOS applications. A class library may use other class libraries. to use it, you must download other class libraries. Other class libraries also use other class libraries ", this may be a special case. In short, it is very troublesome to manually download the required class libraries one by one. Another common situation is that the class libraries used in your project are updated. You must download the new version and add it to the project again, which is very troublesome. If you have any tools to solve these annoying problems, it will be "easy to understand ". So you need CocoaPods.
CocoaPods should be the most commonly used and famous class library management tool for iOS. The two annoying problems mentioned above can be completely solved through cocoaPods with only one line of commands, the premise is that you must set it correctly. Most famous open-source libraries support CocoaPods. Therefore, as iOS programmers, it is essential to master the use of CocoaPods.
How do I download and install CocoaPods?
Note: To use CocoaPods, You need to download and install CocoaPods. to download and install CocoaPods, you need the Ruby environment.
1. Ruby environment Installation
1.1.Ruby Version is too low. RVM (Ruby Version Manage is Ruby Version management) is used to upgrade Ruby
// 1. Install RVMcurl-L get. rvm. io | bash-s stable // 2. After a period of time, you can install RVMsource ~ /. Bashrc // 3. Test whether rvm-v is installed normally.
1. 2. Upgrade Ruby with RVM
// List known ruby versions rvm list known // install the latest ruby version rvm install
1. 3. view the ruby version
ruby -v
2. cocoaPods Installation
2. 1. Switch the cocoaPods Data Source
// Delete the old data source gem source -- remove https://rubygems.org//another new data source gem source-a https://ruby.taobao.org///#data source gem source-l
2. Install cocoaPods
// Install cocoaPodssudo gem install cocoapods // configure the repository pod setup
// The download is complete. You can view the version number.
Pod -- version
CocoaPod usage
2.1.1. Search for open source libraries
pod search AFNetworking
2.1.2. Add a third-party library,
A. Create a project
B. cd in the terminal to the project's total directory
C. Create a Podfile (configuration file) vim Podfile
D. Enter I on the keyboard to enter the editing mode.
E. After editing, Press Esc and enter ":" to enter the vim command mode. Then, enter wq behind the colon to save the settings.
F. Enter pod install to start third-party installation.
- About Podfile file editing
A. Writing normally
Platform: ios, '8. 0' target: 'Project name' dopod 'third-party library name', 'version'
End
B. If different targets require different dependent libraries, you can
platform :ios target :'FirstTarget' do pod 'Reachability' pod 'SBJson' pod 'AFNetworking' end target :'SecondTarget' do pod 'OpenUDID' end
C. Various methods for writing third-party library version numbers:
Pod 'afnetworking' // If the dependent library version is not explicitly specified, the latest pod 'afnetworking' and '2 are obtained each time. 0' // only use pod 'afnetworking' of Version 2.0, '> 100' // use pod 'afnetworking' of version higher than 2.0 ', '> = 2.0' // use the pod 'afnetworking' of a version greater than or equal to 2.0, '<2.0' // use the pod 'afnetworking' of a version earlier than 2.0 ', '<= 2.0' // use the pod 'afnetworking' version earlier than or equal to 2.0, '~> 0.1.2 '// use a version later than or equal to 0.1.2 but less than 0.2, which is equivalent to> = 0.1.2 and <0.2.0pod 'afnetworking',' ~> 0.1 '// use the pod 'afnetworking',' ~> 0' // a version later than 0. Writing this limit and nothing is an effect, indicating that the latest version is used.
Problems During CocoaPod Installation and Use
A. No Target specified in the project
B. the compiling rules for Podfile are incorrect.
C. The path is changed because multiple Xcode is installed.
.
Solution
Sudo xcode-select-switch/Applications/Xcode. app Note:/Applications/Xcode. app: This part is not in the path of Xcode. Find the installation path of Xcode and drag it in.
D. When the database is imported normally, but the relevant header file still cannot be found, which restricts our development efficiency, you can:
In TARGETS-> Search Paths-> User Header Search Paths, write $ {SRCROOT} and change the following parameter to recursive:
E. After the installation starts, the following situations may occur. This step usually takes some time. During the installation process, if you want to view the download progress, run the following command to view the download progress:
// Enter the CocoaPods directory cd ~ /. Cocoapods // view the file size and view du-sh once every several minutes *
The above problems are my current problems. Please help me to add them.