IOS cocoapods Details of the production article _ios

Source: Internet
Author: User
Tags commit documentation git clone

After learning to use someone else's pods dependency library, you must be tempted to create your own dependency library today to uncover the mystery of the pods-dependent library creation process. The entire creation process is an example of a view I've implemented that is called the Wzmarqueeview, and the steps are as follows:

First, create your own GitHub warehouse

Cocoapods are hosted on GitHub (official link: https://github.com/CocoaPods), all pods dependent libraries are also dependent on GitHub, so the first step is to create a GitHub warehouse of their own. The warehouse creation interface is shown below:


The above figure has a total of 6 of the serial number, corresponding to the following description:

1, Repository name

Warehouse name, here written Wzmarqueeview, must be filled;

2, Description

Description information of the warehouse, optional;

3, the openness of the warehouse

Here can only choose public, one is because private is to money, and then a private other people can not see also share a hair;

4, whether to create a default readme file

A complete warehouse, all need readme documentation, recommended selection. Of course it's not too much trouble. You can also manually create one later;

5. Whether to add. gitignore files

A number of file types are documented in the. gitignore file, and Git does not include the file types that it contains in version management. Whether to choose to look at personal needs;

6, License type

Regular warehouses should have a license file, pods rely on the library for this document more stringent requirements, is necessary. So it's best to let GitHub create one here, or you can create it yourself later. The type of license I use is MIT.

The above items are completed, click the Create Repository button, create a successful interface as shown:


By this, the warehouse creation process is over.

Second, the clone warehouse to the local
In order to facilitate the deletion of content to the warehouse, you need to first the warehouse clone to the local, operating a variety of ways, the recommended use of the command line:

$ git clone https://github.com/wangzz/WZMarqueeView.git

When the operation is complete, the corresponding files on the GitHub will be copied to the local directory structure:

The. gitignore file in the GitHub warehouse is a hidden file with a. Beginning, so you can see only two.
All of our documents are added, deleted and changed in this catalogue.

Add the required files to the local git warehouse to create pods dependent libraries

Note: The files described below should be placed under the root directory of step two clone to the local git warehouse.
1, suffix is. podspec file
This file is a description file for the Pods dependent library, and each pods dependent library must have and only one description file. The file name is consistent with the library name we want to create, and my Wzmarqueeview dependent library has a file name of Wzmarqueeview.podspec.
1.1 Podspec File Contents

The contents of the Wzmarqueeview.podspec are:

Pod::spec.new do |s|
 S.name = "Wzmarqueeview" s.version = "1.0.0" s.summary = "A marquee view used on IOS."
            S.description = <<-desc It is a marquee view used IOS, which implement by Objective-c. DESC s.homepage = "Https://github.com/wangzz/WZMarqueeView" # s.screenshots = "Www.example.com/screenshots_1", "W      Ww.example.com/screenshots_2 "s.license = ' MIT ' S.author = {" Champions Week "=>" wzzvictory_tjsd@163.com "} S.source = {: Git => "Https://github.com/wangzz/WZMarqueeView.git",: Tag => s.version.to_s} # s.social_media_url = ' HT Tps://twitter.com/name ' S.platform =: iOS, ' 4.3 ' # s.ios.deployment_target = ' 5.0 ' # s.osx.deployment_target = ' 10.7 ' S.requires_arc = True s.source_files = ' wzmarqueeview/* ' # s.resources = ' Assets ' # s.ios.exclude_files = ' Classes /osx ' # s.osx.exclude_files = ' Classes/ios ' # s.public_header_files = ' classes/**/*.h ' s.frameworks = ' Foundation ', ' Co Regraphics ', ' Uikit '

End 

The file is a Ruby file, and the entries in it are easy to know.
A few more parameters to be described:
①s.license
Pods rely on the library to use the type of license, we fill in their own corresponding choice.
②s.source_files
Represents the path of the source file, note that this path is relative to the Podspec file.
③s.frameworks
Need to use the frameworks, do not need to add the. Frameworks suffix.

1.2 How to create a Podspec file

There are two ways you can create your own Podspec files:
①copy my Podspec file and then modify the corresponding parameters, recommend this approach.
② execute the following create command:

$ pod Spec Create Wzmarqueeview

A file named Wzmarqueeview.podspec is also created. But when you open the created file, you will find that there are so many things that we don't need.

2, License documents
Cocoapods force requires that all pods dependent libraries must have license files, otherwise validation will not pass. There are many types of license, the details can refer to the website tl;dr Legal. When I created the GitHub warehouse, I had selected the MIT type of license.

3. Main class files
Create pods rely on the library is to facilitate others to use our results, such as I want to share to everyone Wzmarqueeview class, is I want to provide to the vast number of users, this kind of nature is essential. I put the two files contained in this class in a folder called Wzmarqueeview, and the corresponding directory structure is as follows:

Contains two files: WZMarqueeView.h and WZMARQUEEVIEW.M

4. Demo Project
In order to quickly teach others to use our Pods dependency library, it is often necessary to provide a demo project. The demo project I created was put into a folder called Wzmarqueeviewdemo, which contains files as shown in the following illustration:

5, Readme.md
People using GitHub should be familiar with this file, which is an essential part of a successful GitHub warehouse, using the Markdown Markup Language, for detailed instructions on the warehouse.

The 5 mentioned above are the most basic files needed to create a pods dependent library, where 1, 2, and 3 are required, 4, 5 are optional but strongly recommended.
After you have added these files, my github local warehouse directory will look like the following image:

Iv. submitting modified documents to GitHub
After step three, add a lot of files to the local git repository and now need to submit them to the GitHub warehouse. The submission process is divided into the following steps:
1. Pod Verification
Execute the following command:

$ set the new version to 1.0.0
$ set the new tag to 1.0.0

These two commands add a version number to the pod and tag. Then execute the pod Validation command:

$ pod Lib Lint

If everything works, the following output appears after the command is executed:

 -> Wzmarqueeview (1.0.0)

Wzmarqueeview passed validation.

By this, pod verification is over.
What needs to be explained is that when the pod Validation command is executed, any warning or error information is printed and the validation fails! If there is an exception to the validation, the printed information will be very detailed, you can make changes according to the corresponding prompts.

2, local git warehouse modified content uploaded to GitHub warehouse
Execute the following command sequentially:

$ git add-a && git commit-m "release 1.0.0."
$ git tag ' 1.0.0 '
$ git push--tags
$ Git push origin master

These commands are in the domain of git and are not covered here. If everything is OK, GitHub should be able to see what they have just added. As shown in the following illustration:

V. Upload podspec files to cocoapods official warehouse
After four steps, you might think it's over, unfortunately it's still early.

To make a pods dependent library truly available, you need to do one last step to upload the Podspec file we just generated to Cocoapods's official Specs warehouse, which links to: Https://github.com/CocoaPods/Specs

Open this link and you will find that all of the pods dependencies that we can use, and all the libraries we can search using the pod Search command, will upload their podspec files to the warehouse, which means that only after uploading our podspec files to the warehouse, Can become a real pods dependent library, others can be used normally!

According to Git's rules, to add a file to someone else's warehouse, you must first fork a warehouse of someone else's, finish modifying it, push it to the original author of the warehouse, wait for the author to approve it, and then merge it into the original warehouse.

After the process is understood, nature knows what to do:
1, fork a Cocoapods official specs warehouse
into the official warehouse link just now, click on the Fork button in the upper right corner of the screen, as shown below:



Then you will find that you have one more branch of the warehouse under your name. For example, my branch is:

2, will fork warehouse clone to the local
Execute the following command:

$ git clone https://github.com/wangzz/Specs.git

Note that you need to change the corresponding warehouse address for your own.
This warehouse is a bit big and needs patience.

3, add their own podspec files to the local specs warehouse
After the Specs warehouse clone is local, it is placed in a folder named specs. The principle of saving the Podspec file in the Specs warehouse is:
Pods a folder with the same name---> Version number folder--->podspec file
In this principle, I need to create a folder named Wzmarqueeview under the Specs folder, and then go to the Wzmarqueeview folder, Create a folder called 1.0.0, and finally go to the 1.0.0 folder and copy the Wzmarqueeview.podspec file that you created before.
It is not difficult to understand that if you have an upgrade to the Wzmarqueeview class later, you can create a folder of the corresponding version name in the Wzmarqueeview folder to save the corresponding version of the Podspec file.
When these operations are complete, the directory hierarchy looks like this:

4, upload the local specs warehouse changes to the GitHub warehouse
Execute the following command:

$ git add-a && git commit-m "add wzmarqueeview podspec file"
$ Git push origin master

After the success of the GitHub on their own fork specs warehouse to see the file just uploaded.

5, will be in their own fork specs modification pull to cocoapods official specs Warehouse
into your own fork specs warehouse, you will see a green button in the upper-left corner of the screen:


When the button is clicked, there will be an interface as shown in the following figure:

Click on the green Create Pull request button in the map, you can fork our specs on the changes Pull to cocoapods the official specs warehouse.

By this step, the rest of the work will have to wait, waiting for Cocoapods's maintenance staff to review and merge our pull changes into the official specs warehouse, which usually has a day or so waiting time. If there is any news, such as the audit does not pass, or audit passed, Cocoapods will send an e-mail notification.
By the time the audit passes, we will be able to see the uploaded folders in the official specs warehouse.

6, review the progress of the audit
Of course we can also check the progress of audit, open this link: https://github.com/CocoaPods/Specs/pulls, here you can see all the Specs warehouse pull request, the following figure:

Red Circle logo is I just pull up the request, point in the future will be able to see the corresponding audit progress.

Vi. View the Pods dependency libraries we created ourselves
If you receive an audit from the official cocoapods, you may be anxious to execute the pod Search command on your computer to see if you can search for a pods dependency library that you have created. You'll be disappointed, though, because you'll need to execute a command to search our dependent libraries using the search command on our local computer:

$ pod Setup

The first of my Cocoapods series tutorials: Cocoapods The last part of the Advanced chapter introduces the command, which will all pods depend on the library tree to the new local. After executing this command, execute:

$ pod Search Wzmarqueeview

will be able to display the corresponding introductory information!

Said so much, to be here the entire Pods dependency library creation process is really over! Little friends, have you succeeded??? Please leave a message when you have problems.

Vii. reference Documentation

1, http://guides.cocoapods.org

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.