The latest CocoaPods private library


Some of the components in the project need to be split, because these components need to be used in different APP (for example: image upload module, tool library, etc.). Therefore, in order to unify the management and do not expose the core of the code, we decided to use CocoaPods to establish a unified management of private warehouses, that is, the component. The benefits of the component is more clear division of labor, improve the efficiency of development, reusability is better, can quickly form more APP.

Making private libraries

1, create a private warehouse

Here I built a private warehouse on coding


2, add private warehouse to the local pod Library

Pod repo add QMiOSRepo

After success, we can look at:
open ~/.cocoapods/repos

The latest CocoaPods private library
private warehouse

here more than one of our private libraries QMiOSRepo

3, create the project QMKit git private warehouse


4, the establishment of pod Engineering

Pod lib create QMKit

There will be a series of questions during the process of creation:

What is your email 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]? What is your class prefix?

After completing a series of inquiries, you can see the current directory of the QMKit folder

The latest CocoaPods private library

5, edit the podspec file
podspec described their component engineering code directory and resource directory in which, also has its own component engineering relies on other frameworks, we will according to the podspec guidelines to introduce its own warehouse code. Here we can see a file named QMKit.podspec in the QMKit directory.

Be sure to # # run `pod lib lint QMKit.podspec'to ensure this is a valid spec before submitting. # # # Any lines starting with a are optional but #, their use is encouraged To more about a # learn Podspec see podspec.html # / / s representative index: do library Pod: |s| / /'QMKit' / / = set name set the version number s.version ='0.1.0'/ s.summary ='A short description set up the of QMKit.' This is used to # description generate tags and improve search results. What does it # * Think: do Why did you? Write it? What is the focus Try to keep? # * it short, snappy and to the point. # * Write the description between the DESC delimiters below. # * Finally, Don't worry about the indent, CocoaPods strips it! S.description = < < -DESC TODO: Add long description of the pod here. DESC / / s.homepage =''home page set up warehouse # s.screenshots =' screenshots_1'''/ / set license, can not fill in, there must be agreement like this: type s.license = {'MIT', => file: =>'LICENSE'} {'QinminiOS' = =>} / /'[email protected]'QMKit git private warehouse address: git {s.source = =>'': tag => s.version.to_s;} # s.social_media_url ='< TWITTER_USERNAME& Gt; s.ios.deployment_target'8.0'=' / / set the source file path s.source_files ='QMKit/Classes/**/*'s.resource_bundles ='QMKit' # # {=>}; ['QMKit/Assets/*.png'] s.public_header_files ='Pod/Classes/**/*.h'# # # s.frameworks ='UIKit','MapKit'# s.dependency'AFNetworking','~> 2.3'end

6, submit code, and play tag

Git add. Git -m first git add git -u origin master git tag 0.0.1 git push --tags remote commit origin push commit

7, check the pod library is available

Pod lib lint if a warning can be used to ignore the command: pod lib lint --allow-warnings
  • If you encounter [An] unexpected directory was encountered the etc App.lproj… This similar error indicates that the cocoapods version is relatively low with gem install cocoapods –pre update retry for
  • If you encounter other problems we can use pod lib lint –verbose compiler errors and troubleshooting.

8, submitted to the QMKit.podspec QMiOSRepo

Go to the QMKit directory and execute the following command

Pod repo push QMiOSRepo QMKit.podspec

9, check whether the pod library is available

New QMTest project, the preparation of Podfile files, specify the first look for our warehouse QMiOSRepo.git

Source''platform:ios,'8.0' target do pod'QMKit','~> 0.1.0' end ('QMTest')
  • If this error: [] An unexpected version directory! Assets was encountered for the
    ~/.cocoapods/repos/QMiOSRepo Pod in the QMiOSRepo repository. may be the private warehouse address is wrong, may also be submitted to the QMiOSRepo QMKit.podspec failure.

Resource processing

If the component uses a resource, be sure to generate the component framework, can not generate a static library, or resources can not get.

  • In the use of pod lib create to create the components of the project, will create Assets folder, the picture, the resources put in this directory.
The latest CocoaPods private library
  • Podspec then specifies the resource file path s.resource_bundles
S.resource_bundles = {'QMKit'=>}; ['QMKit/Assets/*.png']}
  • Podfile file to add a description of use_frameworks, the role is to generate frameworks library.
Use_frameworks! Source platform:ios'','8.0''QMTest'do pod'QMKit','~> 0.1.1'end target
  • Load image resources. Resources will eventually be copied to the QMKit.framework in QMKit.bundlke.
NSBundle *bundle = bundleForClass:[self class]]; NSString *path = pathForResource:@ ofType:nil] "QMKit.bundle/1.png"; _imageView.image = [UIImage imageWithContentsOfFile:path] [bundle ([NSBundle);
Location of The latest CocoaPods private library
resources in framework
Location of The latest CocoaPods private library
framework in app

Reference article