Create a private index library from the pocket CocoaPods


What is an index library? Why do you want to create a private index library? The terminal inputs pod repo, and if the previous configuration has not been configured, the output information is:

Master - Type: git (Master) - URL: - Path: /Users/Jack/.cocoapods/repos/master

Open the browser, you can see a Specs folder, the folder contains all the support framework of CocoaPods index, but the is open the index, you can only add open (open) framework, if want to let private frame support CocoaPods, this time must use the private library.


If the private frame already exists, simply go to the local project root directory, create podspec, upload the correct information, upload the push file, and then podspec the file to the private index library.

Pod spec create [podspec podspec pod to create the file name] lib lint //podspec / pod spec lint //podspec local authentication verification git add. Git commit remote -m XX git push origin master pod repo push [private] [podspec index database file] / / podspec file push to private library

If you create a private framework from scratch, you can follow the following steps:

(take TestLib as an example, please replace it yourself)

The terminal goes into the folder ready to create lib, and executes the command

Pod lib create TestLib

This process may take a few seconds, and then the following information will appear:

What language do you want to use?? [Swift / ObjC] Would you like to include a demo application with your library [Yes / No]? Which testing frameworks will you use? [Specta / Kiwi / None Would you like to do] view based testing [Yes / No]?

According to the prompt input, after completion, will automatically open the corresponding TestLib Example project

Execute the tree command to view the directory structure

01:TestLib Jack$tree TestLib -L TestLib Example, had just 2 Podfile, Podfile.lock Pods, had just had, TestLib, TestLib.xcodeproj, TestLib.xcworkspace had just, Tests - LICENSE - had just had - TestLib / Assets / Classes / Song - - TestLib.podspec - _Pods.xcodeproj -> had; Example/Pods/Pods.xcodeproj 10 directories, 5 files

Put components into TestLib/Classes and delete ReplaceMe.m, enter Example folder, execute pod install, TestLib corresponding Example project has been loaded, and can carry on demo demonstration. Later, every time you update lib, you need to go into Example and execute pod install to get the latest code

Create a private index library from the pocket CocoaPods
  • Creating a remote private library

Since GitHub creates a private library, you need to pay for it. Here’s a demo with coding

Create a private index library from the pocket CocoaPods
remote private library

Here, open source license, gitignore does not need to add the directory structure of TestLib from above can see, pod lib create has created the three files, if added, when commit may lead to a conflict (the contents of the file are not identical), so as to create a clean private library.

  • Modify the podspec file
Pod:: do |s| ='TestLib's.version ='0.1.0' s.summary ='TestLib's.description = < < -DESC TestLib is a demonstration of DESC ='' s.screenshots s.homepage # ='','' = {s.license: type =>'MIT', file: =>'LICENSE' = {'01_Jack'}} {s.source = =>'': Git =>'', tag: => s.version.to_s} # s.social_media_url ='< TWITTER_USERNAME> ='8.0'; s.source_files ='TestLib/Classes/**/* 's.ios.deployment_target '# s.resource_bundles = {'TestLib' =>} # #; ['TestLib/Assets/*.png'] s.public_header_files ='Pod/Classes/**/*.h's.frameworks ='UIKit''MapKit'# #, s.dependency'AFNetworking','~> 2.3'end
  • Local authentication of podspec:
Pod lib lint --private

If Waring validation does not pass, you can add –allow-warnings, remote authentication, and pod repo push

  • Pack

After verification, packaged class library, here you can use cocoapods plug-in cocoapods-packager to complete (manual packaging too troublesome). If you do not have cocoapods-packager installed before, execute the following command:

Sudo gem install cocoapods-packager


Pod package TestLib.podspec --force

The default package is.Framework, and if added to the –library, it is packaged as.A.

After verification, you can view the current git change status through the GIT status, and no files that need to be submitted can be added to the gitignore.

Git, status, GIT, add, GIT,, commit, -m,'first, blood'

Here you can already submit your code to the remote warehouse, but you need to add the warehouse address before submitting it

  • Add public key

Add the generated public key to the account

Create a private index library from the pocket CocoaPods
adds the public key
Git, remote, add, origin,, GIT, push, origin, master

Before you do remote validation of podspec, you must first push tag, and tag must be consistent with the version in podspec

Git, tag, 0.1.0, GIT, push, --tags, pod, spec, --private, lint

After remote authentication, TestLib.podspec push is passed to the remote private index library. Similarly, you need to add the warehouse first, and then push

  • Creating a private index library
Create a private index library from the pocket CocoaPods
private index library
Pod, repo, add, PrivateSpecs,, pod, repo, push, TestLib.podspec, PrivateSpecs

At this point, the local index library is long

CD ~/.cocoapods/repos open
Create a private index library from the pocket CocoaPods

The most basic production is done here, and now you can search the TestLib Library

Pod search TestLib
Create a private index library from the pocket CocoaPods
pod search

New project, pod init, modify the podfile file. Here you need to add two source, an original master repo, and a later added PrivateSpecs

Source,'', source, use_frameworks,'', target,'Test', do, pod,'TestLib', end

To execute pod install, you can use the TestLib framework

Tip: if the component contains pictures, audio, video, xib/storyboard, etc., the description of podspec and the wording in the code need to be changed

Go back to the podspec file

S.source_files ='TestLib/Classes/**/*'s.resource_bundles ='TestLib' => # # {['TestLib/Assets/*.png']} #;

S.source_files is used to find code, and s.resource_bundles is used to find resources.
TestLib/Classes/**/* represents all files that match all subdirectories under the TestLib/Classes folder

  • * match all files
  • C* matches all files that start with C
  • *c matches all files that end with C
  • *c* matches all files that contain C
Pattern: * * *
  • * * recursively matches all subfolders

Before you load the components, you can load pictures, audio, video, xib/storyboard and other resources through the mainBundle. Now you want to get the resources through the component bundle. TestLib automatically routes the specified path resources under s.resource_bundles to bundle packages and is named TestLib.bundle

Create a private index library from the pocket CocoaPods

However, you don’t have to put the resources under the Assets folder, which can be any folder (such as Classes or new in the directory structure), as long as you can find the resources. Similarly, if you include the resource s.source_files, write it this way:

S.source_files ='TestLib/Classes/**/*{.h,.M}'

If you don’t write this, if you include a resource file in Classes, it will cause a crash. At this point, first find the TestLib.bundle, and then load the resources from this bundle

NSBundle *bundle / / bundle resource acquisition bundleForClass:[self class]] = [NSBundle;

Podspec also has some common uses, such as subspec, dependency, vendored_frameworks, vendored_libraries, prefix_header_contents, prefix_header_file, and so on

Podspec more configuration, you can refer to Podspec Syntax Reference

Have fun!