IOS cocoapods Details of the Advanced chapter _ios

Source: Internet
Author: User
Tags serialization versions uikit

One, podfile.lock file
generates a Podfile.lock file after you start using Cocoapods and after you perform pod install. This file does not seem to have much to do with us, and it should never be overlooked.
The file is used to save the version of the Pods dependent library that has been installed, and the reachability file content for the cocoapods after installing Sbjson, afnetworking, pods three Podfile.lock dependent libraries is:

 PODS:-afnetworking (2.1.0):-Afnetworking/nsurlconnection-afnetworking/nsurlse Ssion-afnetworking/reachability-afnetworking/security-afnetworking/serialization-afnetworking/uikit-afn
 Etworking/nsurlconnection (2.1.0):-Afnetworking/reachability-afnetworking/security-afnetworking/serialization -Afnetworking/nsurlsession (2.1.0):-Afnetworking/nsurlconnection-afnetworking/reachability (2.1.0)-AFNetworkin
 G/security (2.1.0)-afnetworking/serialization (2.1.0)-Afnetworking/uikit (2.1.0):-Afnetworking/nsurlconnection -Reachability (3.0.0)-Sbjson (4.0.0) Dependencies:-Afnetworking (~> 2.0)-reachability (~> 3.0.0)-SBJSO N (~> 4.0.0) SPEC CHECKSUMS:AFNETWORKING:C7D7901A83F631414C7EDA1737261F696101A5CD reachability:500bd76bf6cd8ff2c 6fb715fc5f44ef6e4c024f2 sbjson:f3c686806e8e36ab89e020189ac582ba26ec4220 cocoapods:0.29.0 

The Podfile.lock file is most useful for many people to develop. The following are the written versions of the Pods dependent libraries that are not specified in Podfile:

Pod ' Sbjson '

This sentence is used to get the latest version of this pods dependent library for the current Sbjson.
When someone on the team finishes the Pod Install command, the resulting Podfile.lock file records the version of the latest Pods dependent library, and then the other people on the team check down the project that contains the Podfile.lock file and then execute the pod Install command, the obtained version of the Pods dependent library is the same as the version that was obtained from the first user. If there are no podfile.lock files, all subsequent users performing the pod install command will get the latest version of Sbjson, which can cause inconsistent versions of the dependent libraries used by the same team, which is a disaster for team collaboration!
In this case, if the team wants to use the current version of the Sbjson dependency library, there are two scenarios:
Change the podfile to point to the latest version of the Sbjson dependency library;
Execute pod Update command;
Since Podfile.lock files are so important to team collaboration, we need to add it to version management.

Second, podfile documents
For ordinary users, the most cocoapods we deal with is podfile files. Cocoapods is implemented in Ruby, so the syntax of the Podfile file is Ruby's. Then introduce podfile from the following aspects:
1, podfile file storage location
This is a problem left over in the last article. Typically, we recommend that podfile files be placed in the engineering root directory, as shown in the following illustration:

In fact, podfile files can be placed in any directory, what needs to be done is to specify the path of the project in Podfile, compared to the original Podfile file in the beginning of the position added a line, the details are as follows:

Xcodeproj "/users/wangzz/desktop/cocoapodstest/cocoapodstest.xcodeproj"

platform:ios 
pod ' Reachability ', ' ~> 3.0.0 ' 
pod ' Sbjson ', ' ~> 4.0.0 ' 
 
platform:ios, ' 7.0 ' 

The specified path uses the Xcodeproj keyword.
After that, enter the path where the Podfile file is located, and the pod Install command will download the pods dependent libraries as before, and the resulting files will be placed under the Podfile directory, as shown below:

As before, we still need to open the project using the workspace file generated here.

2, Podfile and target
Podfile is essentially used to describe the targets used in Xcode engineering. If we do not explicitly specify that the podfile corresponding target,cocoapods will create an implicit target named default, it will correspond to the first target in our project. In other words, if target is not specified in Podfile, only the first target in the project can use the Pods dependency library described in Podfile.
If you want to describe multiple target in project in a podfile, you can have different implementations depending on your requirements. To illustrate the problem, create a target named second in the original project, and now the target contained in project is:

① use the same pods dependent libraries in multiple target
For example, Target and second with name Cocoapodstest need to use reachability, Sbjson, afnetworking three pods dependent libraries, which can be implemented using the Link_with keyword. Write the podfile in the following ways:

Link_with ' cocoapodstest ', ' Second '
platform:ios 
pod ' reachability ', ' ~> 3.0.0 ' 
pod ' Sbjson ', ' ~> 4.0.0 ' 
 
platform:ios, ' 7.0 ' 

This notation achieves the same pods dependent libraries as the cocoapodstest and second two target shares.
② different target uses a completely different pods dependency library
Cocoapodstest This target uses reachability, Sbjson, and afnetworking three dependent libraries, but second this target only needs to use Openudid, a dependent library, At this point, the target keyword can be used, and the podfile is described in the following way:

Target: ' cocoapodstest ' do
platform:ios 
pod ' reachability ', ' ~> 3.0.0 ' 
pod ' Sbjson ', ' ~> 4.0.0 ' 
 
Platform:ios, ' 7.0 ' 
pod ' afnetworking ', ' ~> 2.0 '
end

target: ' Second ' do
pod ' Openudid ', ' ~> 1.0.0 ' End

Where Do/end as the start and end identifiers.
3, using Podfile management Pods Dependent library version
When you introduce a dependent library, you need to display or implicitly indicate the referenced version of the dependent library, and the specific wording and meaning are as follows:

Pod ' afnetworking '   ///Do not explicitly specify dependent library version, means get Latest version of
pod ' afnetworking ', ' 2.0 '   //Only use 2.0
pod ' Afnetworking ', ' > 2.0 '   //using a version above 2.0
pod ' afnetworking ', ' >= 2.0 '   //using a version greater than or equal to 2.0
pod ' Afnetworking ', ' < 2.0 '   //use of a version less than 2.0
pod ' afnetworking ', ' <= 2.0 '   //use of a version less than or equal to 2.0
pod ' Afnetworking ', ' ~> 0.1.2 '   //use of versions greater than or equal to 0.1.2 but less than 0.2
pod ' afnetworking ', ' ~>0.1 '   // Use a version greater than or equal to 0.1 but less than 1.0
pod ' afnetworking ', ' ~>0 '   //higher than 0 version, write this limit and write nothing is an effect that all means to use the latest version

Three, Cocoapods common command
1. Pod Install
Depending on the content specified by the Podfile file, the dependent library is installed, and if there is a Podfile.lock file and the corresponding Podfile file has not been modified, it will be installed according to the version specified by the Podfile.lock file.
Each time the Podfile file is updated, the command needs to be rerun to reinstall the Pods dependent library.
2. Pod Update
If the dependent library version specified in Podfile is not written dead, when the corresponding dependent library has been updated, no Podfile.lock file will be available to obtain the latest dependent library version that is allowed for Podfile file description.
3. Pod Search
The command format is:

$ pod Search Openudid

The openudid behind is a parameter.
It is easy to see from the name of the command that the command is used to search for an available pods dependent library by name, and the results are as follows:

-> Openudid (1.0.0)
  Open Source Initiative for a universal and persistent UDID for IOS.
  Pod ' Openudid ', ' ~> 1.0.0 '
  -homepage:http://openudid.org
  -Source:  https://github.com/ylechelle/ Openudid.git
  -versions:1.0.0 [master repo]

Here we have found a usable data, which describes the Openudid Library's brief information. Actually what we really need is the third line of the results:

Pod ' Openudid ', ' ~> 1.0.0 '

It's not hard to see that this is what we need to add to the Podfile file.
With this command, you can easily and quickly find the pods dependent libraries you need.
4. Pod Setup
The command format is:

$ pod Setup

It will print after execution:

Setting up cocoapods master repo
updating 7cd4668. f3d3ced

Fast-forward

The next step is to print a lot of update information.
This command is used to rely on the library tree on the saved pods on the new local computer. Since many people create or update pods dependencies every day, the command is slow to execute, and please be patient. We need to execute this command frequently, otherwise the pod Search command is not available when there is a new pods dependent library.

Iv. reference Documentation

Http://guides.cocoapods.org/using/index.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.