Use Cocoapods to create private podspec and cocoapodspodspec

Source: Internet
Author: User

Use Cocoapods to create private podspec and cocoapodspodspec
Initially

Third-party open-source libraries are inevitable for iOS project development. There are basically two reference methods:

Method 1: drag the file directly into the project.

Method 2: CocoaPods management.

We create a repository on Github or Coding, place our library code, and the directory structure becomes like this


 

When used, clone it and drag it into the project. Method 1

Body

Method 2: import the database using pod install. Therefore, you need to have a podspec file with the same name under the root directory of this database. The directory structure is like this.


 

The function of podspec is to tell the pod how to introduce the library during pod install. Some parameters in this file need to be set.

 


 

Configure Podfile and install it.

 


 

Now we can use pod install to introduce our library.

Pod automatically creates a project

You can use the command line to automatically complete the steps of creating library files, testing projects, and podspec.

Enter pod lib create TestPrivateCodeRepo on the terminal. CoccoaPods will ask a few questions.

Language to use

Sample project required?

Whether a test framework is required

Whether View-based testing is required

Class prefix

Then the created Project is automatically opened.


Put component-related classes in the project. This path is specified when the podspec file is configured.

 


 

Cd to the root directory of TestPrivateCodeRepo, push the resource file of this version, and tag it (label used for pod install specified version)

Pod add. // add all files

Pod commit-am "descrube" // put it in the cache to prepare push

The local git library is directly generated by pod lib create TestPrivateCodeRepo, which is equivalent to the direct git init and has not yet been linked to the remote library.

Pod remote add origin https://git.coding.net/jxlucky/TestPrivateCodeRepo.git

Pod pull <database address> master

Pod status // check whether there is something to submit

Pod add.

Pod commit-am "f c 1"

Pod push origin master

Pod tag-m "tag describe" 0.1.0 // tag

Pod push -- tags // push tag

Local podspec Verification

Cd Example

Modify the Podfile File

 


 

Pod install

Now we can introduce our own library in the form of pod install.

Note: We need to modify this in the Podfile of our work project.

Pod 'testprivatecoderepo ',: git => 'git address', "tag => '0. 123'

Pod 'testprivatecoderepo 'cannot be used directly,: podspec =>' ../TestPrivateCodeRepo. podspec'

Publish podspec

Create a spec library. The spec library is equivalent to a configuration file library. just create a blank library on Github or Coding.

Pod repo add TestSpecs the git address of the remote Spec library // it serves to create an empty directory TestSpecs, where git clone the git address of the remote Spec Library

Cd to the TestPrivateCodeRepo root directory to verify podspec

Pod lib lint TestPrivateCodeRepo. podspec

If the verification succeeds, podspec will be released.

Pod repo push TestSpecs TestPrivateCodeRepo. podspec

In this case, the remote Spec library and local ~ /. Cocoapods/repos/TestSpecs path has been updated.

Test

Create a project pod init> edit Podfile

Source 'https: // github.com/CocoaPods/Specs.git'

Source 'our own spec library. git'

Use_frameworks!

Target 'anproject' do

Pod 'testprivatecoderepo'

End

Finally,

Execute pod repo update TestSpecs when TestSpecs is used for updates, and synchronize the remote spec Library to the local

 

 

Problem Encountered

1. [!] appears during pod search Unable to find a pod with name, author, summary, or description matching

Solution: rm ~ /Library/Caches/CocoaPods/search_index.json and search again

 

2. [!] The repo 'myspecs' at '.../. cocoapods/repos/MySpecs' is not clean Error

Solution: cd ~ /. Cocoapods/repos/MySpecs, git clean-f

 

Links:

Blog.wtlucky.com/blog/2015/02/26/create-private-podspec/

Www.open-open.com/lib/view/open1469488701199.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.