“This is the 19th day of my participation in the First Challenge 2022, for more details: First Challenge 2022”.
preface
- IOS CocoaPods private library
- using
pod lib
Develop and package the iOS static library
Background: I built a template by myself and used git_subtree for management; Recently I’ve enjoyed developing packaged static libraries using cocoaPods.
- A static library template that you built before
Develop a static library that uses git_subtree to manage dependencies
- The point of this article is to change
pod lib
Create a project template for developing static class libraries and use itpod package
To pack;
1) Use: Podlib Lint Verify format pod lib Lint knpodlib. podspec –verbose –allow-warnings 2) Publish pod trunk push with pod trunk push KNPodlib.podspec –verbose –allow-warnings
Open source: Github Code
🍅 Contact author: iOS Reverse (public number: iosrev)
I. IOS CocoaPods private library
If you want to build your project in the future, you can use the iOS CocoaPods private library to do so
1.1 Procedure
-
Create a private Git remote repository to store code
-
Create a private CocoaPods remote index library (used to store code with version information similar to CocoaPods)
pod repo add CocoaPodsIndex https://github.com/CocoaPodsIndex/CocoaPodsIndex.git
Copy the code
-
Create Pod required project files, and upload to Git remote private library;
-
Verify the PodSpec description file;
-
Submit the PodSpec description file to the private CocoaPods remote index library
-
Use Pod library;
1.2 PodSpec describes the key configuration parameters of the file
- KNGotoSafari.podspec
s.source_files = 'KNGotoSafari/Classes/**/*'Knpodlib.bundle s.bundle = {knpodlib.bundle s.bundle = {'KNGotoSafari'= > ['KNGotoSafari/Assets/*.png']
}
s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'# if there are multiple third party dependencies: there are multiple third party libraries, write multiple s.dependency'ReactiveObjC'
s.dependency 'Masonry'.'~ > 1.1.0'
Copy the code
II、 CocoaTouchStaticLibrary
2.1 Static library development using Xcode template
- Not manually created based on POD (deprecated), I used it for a long time and explored a set of templates myself
Xcode->Cocoa Touch Static Library [Optional]: Create podfiles and execute Pod Install to complete the project [optional]: Demo uses POD to add dependencies on private Static librariesCopy the code
Automatically created based on POD
pod lib create
2.2 Generate a local private library using pod Lib create
- Example reference
KNPodlib
Just enter the pod lib command to complete the initial project setup
- Commands:
+ create Creates a new Pod + lint Validates a Pod Copy the code
2.3 Command preview for packaging static Libraries:
- pod lib create
➜ lib pod lib create KNGotoSafari
Copy the code
https://kunnan.blog.csdn.net/article/details/103830544 ➜ lib pod lib create KNGotoSafari Running pod install on your new library. Analyzing dependencies Fetching podspecfor`KNGotoSafari` from `.. / 'Downloading dependencies Installing KNGotoSafari (0.1.0) Generating Pods Project Integrating Client project [!] Please close any current Xcode sessions and use `KNGotoSafari.xcworkspace`for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
Ace! you're ready to go! We will start you off by opening your project in Xcode open 'KNGotoSafari/Example/KNGotoSafari.xcworkspace' To learn more about the template see `https://github.com/CocoaPods/pod-template.git`. To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.Copy the code
- pod install
➜ Example git:(master) qualify pod install Analyzing dependencies Fetching podspecfor`KNGotoSafari` from `.. / 'Downloading dependencies Installing KNGotoSafari 0.1.0 Installing ReactiveObjC (3.1.1) Generating Pods project Integrating client project Sending stats Pod installation complete! There is 1 dependency from the Podfile and 3 total pods installed.Copy the code
- Packaging. You will need to install a CocoaPods package
pod package
:pod package KNGotoSafari.podspec --library --force
'➜ KNGotoSafari git:(master) qualify pod package KNGotoSafari. Podspec --library --forceCopy the code
2.4 Using Pod Lib Create Specifies how to use Pod Lib Create
- Getting started
pod lib create KNPodlib 1) Note: To use your own pod-template you can add the parameter --template-url=URL where URL is the git repo containing a compatible template. 2)Second Note: you can press return to select the default (underlined) option. Copy the code
- Objective-C or Swift
For both choices CocoaPods will set up your library as a framework. Copy the code
- Making a Demo Application
This means you don't have to go through creating a new project in Xcode. If you want to have an example project for pod try MyLib or need to have your library's tests run inside an application ( interaction tests, custom fonts, etc ) then you should say yes. A good metric is "Should this Pod include a screenshot?" ; if so, then you should have a demo.Copy the code
- Choosing a Test Framework
1) in Objective-C we include a choice of two popular testing frameworks; Specta/Expecta and Kiwi. If you can't decide, use Specta/Expecta. We include all the necessary includes and setup for your testing framework in MyLib-Tests.pch so that you don't have to include them in each file. 2) In Swift we only offer the choice of Quick/Nimble as this looks to be the dominant testing library. Copy the code
- Specta/Expecta
A light-weight TDD / BDD framework for Objective-C & Cocoa. Copy the code
- Kiwi
a Behaviour Driven Development library for iOS development. The goal is to provide a BDD library that is exquisitely simple to setup and use. Copy the code
- View-based Testing
We recommend using FBSnapShotTestCase, if you are using Specta/Expecta then we include a Pod to improve the syntax. Copy the code
- Prefixes for Objective-C
We know that Apple is deprecating prefixes, but in reality they still have their place in Objective-C codebases. Copy the code
2. 5 The Pod Lib Create Template
- The Pod Lib Create Template :tree -L 2
Bass Exercises ── Bass Exercises ─ Bass Exercises. Xcodeproj │ Bass Exercises ── Bass Exercises │ ├── ├─ exercises │ ├── Exercises │ ├── Exercises │ ├── Exercises │ ├── Exercises │ ├── Exercises │ ├── Exercises │ ├── Exercises │ ├── KNPodlib. Podspec ├ ─ ─ LICENSE ├ ─ ─ the README. Md └ ─ ─ _Pods. Xcodeproj - > Example/Pods, Pods. Xcodeproj 10 directories, 5 filesCopy the code
Go to the Example folder and execute Pod Install to have the project install dependencies and configure updates
Add the required code to the /Classes file :(corresponding to the source_files directory of xclogstaticdemo. podspec)
III practice
Due to space reasons, more content please pay attention to # small program: iOS reverse, only for you to present valuable information, focus on mobile technology research field; For more services and advice, please follow # publicid: iOS Reverse.
🍅 Contact author: iOS Reverse (public number: iosrev)
🍅 Author profile: CSDN blog expert certification 🏆 international Top 50, Huawei Cloud enjoy expert certification 🏆, iOS reverse public number master
🍅 Resume template, technical assistance. Pay attention to me, all for you.