As iOS developers, Cocoapods is all too familiar. There are plenty of great third-party libraries on Pods that can be easily used in a line of code. Since it’s so convenient, why don’t we upload our own open source library and share it with everyone? So, in this article we will learn how to upload your open source libraries to Cocoapods for other developers to use.
Also: If you don’t already know how to use Cocoapods, I recommend you take a look at my article on Cocoapods Third-party library management tools
#Podspec description file
Assuming you’ve opened your project on Git, tag it (this is not mandatory, but it is strongly recommended, so that you can configure the description file later).
Generate a spec file with the following command:
pod spec create ZXDatePicker
Copy the code
** Note: ** this description file can be placed anywhere without having to upload it in git library
The main contents of this file are as follows:
Pod::Spec.new do |s|
s.name = "ZXDatePicker"
#name: "Name of your library"
s.version = "0.0.6"
# s.sion: "version number tag"
s.summary = "A sample datePicker."
#s.summary: "A brief introduction to the open source library description"
s.homepage = "https://github.com/Goyakod/ZXDatePicker"
Epage: #s.homepage: "Your Git homepage"
s.license = "MIT"
# S.license: "MIT License"
s.author = { "Goyakod"= >"[email protected]" }
# s.thor: {"yourName" => "your email address"}
s.source = { :git => "https://github.com/Goyakod/ZXDatePicker.git", :tag => "0.0.6" }
#s.source: {:git => "git address ", :tag => "tag version"}
s.source_files = "ZXDatePicker/**/*.{h,m}"
#s.source_files: "Source file path"
s.framework = "UIKit"
# s.framwork: "framework of dependencies", use s.framworks if you have multiple dependencies
s.platform = :ios, "7.0"
# supachai panitchpakdi latform: platform
end
Copy the code
* Notes on the contents of the fields above:
1.MIT license is a TXT file with text content. Copy the template from the mit-license.org/ and change the year and your name. 2.Sourcefile, the path must be specified correctly, depending on the current location of the spec file.
After completing all of the above, execute the following command:
pod spec lint yourPodName.podspec
Copy the code
See yourPodName passed Validation after executing the command. That proves that it has been verified. Failed authentication will prompt you with several errors and Warnings. Warnings alone will not pass the verification, so try to solve all problems and verify.
After verification through, go to the ~ /. Cocoapods/repos/master/Specs directory, create your own library name folder, there is a version of the folder, put into the corresponding description file.
Now you can search on your computer and find your library.
In order to make your library searchable, you need to publish it.
Run the following command to register trunk:
pod trunk register [email protected] 'your name' --description='description'
Copy the code
After the above command is executed, your mailbox will receive a verification email, click verify.
Execute the following command in a directory containing. Podspec:
pod trunk push
Copy the code
This command will first validate your local podSpec file, then upload the spec file to trunk, and finally convert your podspec file to the desired JSON file. When you see a JSON file in the directory, it means that your library has been successfully uploaded to pod.
# ZXDatePicker = ZXDatePicker = ZXDatePicker = ZXDatePicker Depends on the mood).