For developers, as their own development experience more and more long, or himself to the research of some aspect, knowledge is more thoroughly, should try to write a file belongs to their own functions, such as: image shuffling, choice of photo albums, file upload download, audio and video, animated UI, automatic layout, refresh data, etc… But how to make your own good open source files support Cocoapods download convenient for yourself, others use it, I believe you will master this skill after reading this article carefully.

Conditions: GitHub account, Trunk account, GitHub Desktop client, Markdown editor

1. Create open source Public repositories

Create any repository you want to open source on the GitHub homepage

Terms included: Gitignore specifies the file type that GitHub does not include in its version management file. The Pods library is more strict about this file.)




The creation steps are shown in figure

Clone to the local GitHub Desktop




Clone local

Open this repository in Finder and see the directory structure as follows




Snip20160717_12.png

2. Create a PodSpec description file

Podspec: This is essentially a Ruby file that contains information about the code author, version number, source code address, dependency libraries, etc. Any open source code that supports Cocoapods must have a Podspec file. This makes it easy for Cocoapods to search for the corresponding Podspec

Create the PodSpec file

Pod Spec Create Project nameCopy the code

Once created, the directory structure you see in the Finder is as follows




Create the podSpec directory structure

Then add your own open source file (the name of the file is recommended) to the project file, or add a Demo written for the open source framework to make it easier for developers to understand, use, etc. (this is not necessary, but I strongly recommend writing a Demo in a wrapped open source file.)




Overall directory structure

When you open GitHub Desktop, you can view the files to be submitted and the historical submission records




Documents to be submitted

Then open and edit your repository’s PodSpec description file




Edit the podSpec description file

The common podSpec parameters are explained as follows:

File type s.equires_arc Whether ARC S.sion is supported current version s.Platform supported platform S.framwork Import dependent framework library S.mary Description of repository functions. Author information. Source file path (relative to podspec file). Epage home address s.ource Specific path s.public_header_files Path of precompiled header files that do not need to be compiledCopy the code

Podspec syntax structure

Pod::Spec.new do |s| ... . S.s ubspec 'subdirectory do | | ss... End s.s ubspec 'subdirectory do | | ss... end endCopy the code

: it from Pod: : Spec. New do | s | start, to the end of the last end each subspec middle to the end is a subdirectory, subdirectories corresponding | | * * middle name can be arbitrary to name, but for use within the subdirectory name must be consistent

Podspec wildcard description

-a {bb, BC}def.{h,m} indicates four files abbdef.h abbdef.m abcdef.h abcdef.m - *.{h,m,mm} indicates all Class/**/*.{h,m} represents all.h. m files in the Class directoryCopy the code
3. Add the corresponding Tag to the source code
  1. Source code on GitHub needs to be tagged with a version number, soCocoapodsThe manager can find yours more accuratelyrepo
  2. throughItermThe commandpushThe source codetagvalue
    Git tag '0.0.1' // version number git pushCopy the code

    Screenshot below:




    Snip20160717_13.png

Go to your GitHub home page

Note: If all the above steps are correct, then the files under Tags and Branches should correspond to each other as follows:




Snip20160717_14.png




Snip20160717_15.png

4. Verify the correctness of the PodSpec file
Pod Spec Lint Project name PodSpec --verboseCopy the code

A screenshot of this success is shown below:




Snip20160717_16.png

Note: any warnings or errors cannot be added to the Spec Repo

5. Push the Trunk to the Cocoapods server

Start by querying your registration information from the Trunk server

pod trunk meCopy the code

A Trunk account exists.




Snip20160717_17.png

If you don’t have a Trunk, create an account

  • Check the current version number of Cocoapods (minimum 0.33)1.0.1
    pod --version / gem list --local | grep cocoapodsCopy the code

    If not, update it

    sudo gem install cocoapodsCopy the code

    registeredTrunk accountPress Enter to open the email link (neededcopy, can not directly click) can be completed

    Pod Trunk Register Full name 'user name' --verboseCopy the code

    Finally, the final step in the open source project support for Cocoapods downloads is accomplished by terminal push of the corresponding PodSpec

    Pod Trunk Push project name podSpecCopy the code

    Screenshot of successful results:




    Snip20160717_18.png

5. Update the local POD dependency library
pod setupCopy the code

The screenshot is as follows:




Snip20160717_19.png

At this point, you can search for open source files you have just submitted




Snip20160717_20.png

  • After successfulCocoapodsThe server will upload itpodspecFile conversion to requiredjsonfile
  • Examine your own open source documentation
  • Go to folder –~/.cocoapods/repos/master/SpecsFind the corresponding JSON file, as shown in the screenshot:




    Snip20160717_21.png

Open json file contents:




Snip20160717_22.png

  • Right now, you can be thereCocoapodsThe officialspecThe corresponding JSON file is found in the file.Cocoapods的SpecThe method is as shown above.

This is the end of the process for making your own open source project to support Cocoapods downloads.

6. Update the repository version

If the description file is modified and the open source file is updated, the steps of updating the warehouse are as follows:

  • Modify thepodspecandtag(Code version number)
  • againtrunktoCocoapodsThe server

I went home early this morning. Recently, I was writing instant messaging IM. I was too busy to read Jane’s book for a long time. If you feel good, remember to give my open source project a star, 😜😜😜, of course, open source files have anything wrong, but also hope to point out more. Well, for this technical point, the article has what don’t understand don’t understand, please leave a message or private letter below, see have time will certainly reply… Good night…

Finally, I’ll link to CocoaPods to install, use and configure private libraries