IOS package dependency management tools

IOS package dependency management tool (part 1) : CocoaPods

IOS package dependency management tool (ii) : CocoaPods principle and knowledge

IOS package dependency management tool (3) : create your own Pod library

IOS Package dependency Management tool (4) : Swift Package Manager (SPM) Introduction

IOS Package dependency Management tool (5) : Swift Package Manager (SPM) Customization

IOS package dependency management tools (6) : CocoaPods VS SPM Summary

One, foreword

We have learned how to use CocoaPods and the basic principles of our project development, we will inevitably need to engineering and componentized, so we need to develop our own POD components, this article will show you how to create your own POD library, and publish to pod Trunk.

Customize the POD library

2.1. Create a POD library

  • Initialize the Pod first

  • Then pod install, the final result is as follows:

  • Create a custom Pod library:
$pod lib create XXXCopy the code

The whole creation process is shown below:

2.2. Pod Template analysis

The picture above is very clear:

  • Create a pod lib and download the pod template.
  • Depending on our input options, we end up with a complete project with “project” + “Pod Library”;
  • The Xcode directory area on the left shows how “project” refers to “Pod Lib”;

2.3. Podfile analysis for Example

If we do not specify a path, pod will automatically find it in the Pod repo. Here, we give a local path and pod will know. Later, we will readjust the directory structure.

2.4. Podspec files

Let’s take a look at the podSpec file

The other information is generated by default according to the information read in git config. It is not accurate, and will be modified when uploading to Git later. If it is only used locally, it can be ignored.

Third, adjust the directory & introduce the project

3.1. Adjust the POD lib directory

Delete as follows, leaving only the files and directories we need:

3.2. Modify podSpec

Pod: : Spec. New do | s | s.n ame = 'PodLogger' s.v ersion = "1.0.0" s.s ummary = 'A Pod library demo' spyware doctor escription = < < - DESC TODO: The Add long description of the pod here. DESC # after modified to want to submit to making Sheldon horowitz at the address on the omepage = 'https://github.com/qingye/PodLogger' s.license = { :type => 'MIT', :file => 'LICENSE'} s.thor = {' github '=> '[email protected]'} s.thor = {:git => 'https://github.com/qingye/PodLogger.git', To_s} s.iso. Deployment_target = '10.0' s.deployce_files = 'PodLogger/**/*' endCopy the code

3.3 introduction of local projects

Pod install –verbose = pod install –verbose = pod install –verbose

3.4. Implement Logger.swift

public struct Logger { var DEBUG: Bool = false public init(_ DEBUG: Bool) { self.DEBUG = DEBUG } public func log(_ msg: String) { print("Pod.. Logger => \(msg)") } }Copy the code

3.5. Test the POD Lib

4. Go to github


Note: Command line to P o d L o g g e r The root directory \color{red}{note: command line to PodLogger root}

4.1. Create github repository

4.2. Submit & Tag

The operation steps are as follows:

1. git add .

2. git commit -m “xxx”

$ git add . $ git commit -m "pod lib for demo" [master 7256090] pod lib for demo 19 files changed, 38 insertions(+), 1050 deletions(-) delete mode 100644 Example/PodLogger.xcodeproj/project.pbxproj delete mode 100644 Example/PodLogger.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 Example/PodLogger.xcodeproj/xcshareddata/xcschemes/PodLogger-Example.xcscheme delete mode 100644 Example/PodLogger/AppDelegate.swift delete mode 100644 Example/PodLogger/Base.lproj/LaunchScreen.xib delete mode 100644 Example/PodLogger/Base.lproj/Main.storyboard delete mode 100644 Example/PodLogger/Images.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 Example/PodLogger/Info.plist delete mode 100644 Example/PodLogger/ViewController.swift delete mode 100644 Example/Podfile delete mode 100644 Example/Tests/Info.plist delete mode 100644 Example/Tests/Tests.swift rewrite PodLogger.podspec (73%) delete mode 100644  PodLogger/Assets/.gitkeep delete mode 100644 PodLogger/Classes/.gitkeep delete mode 100644 PodLogger/Classes/ReplaceMe.swift create mode 100644 PodLogger/Logger.swift delete mode 120000 _Pods.xcodeprojCopy the code

Git remote add Origin

4. git push origin master

$ git remote add origin https://github.com/qingye/PodLogger.git $ git push origin master Counting objects: 40, done. Delta compression using up to 4 threads. Compressing objects: 100% (33/33), done. Writing objects: 100% (40/40) and 14.39 KiB | 2.05 MiB/s, done. Total 40 (3) delta, reused zero (0) delta remote: Resolving deltas. 100% (3/3), done. remote: remote: Create a pull request for 'master' on GitHub by visiting: remote: https://github.com/qingye/PodLogger/pull/new/master remote: To https://github.com/qingye/PodLogger.git * [new branch] master -> masterCopy the code

Git tag must be the same as your podspec version number.

6. git push –tags

$git tag 1.0.0 $git push --tags Total 0 (delta 0), Reused zero (0) delta To https://github.com/qingye/PodLogger.git * [new tag] 1.0.0 - > 1.0.0Copy the code

4.3 Verify & submit to POD

  1. Validation:pod spec lint --verbose --allow-warnings

  1. If you have not already registered a POD Trunk, you can register it as follows
$POD Trunk register [email protected] 'Pod' --description='Personal PodLib' [!]  Please verify the session by clicking the link in the verification email that has been sent to [email protected]Copy the code
  1. Email address verification

Click the verification link:

  1. Command line view pod accounts
$POD Trunk ME - Name: Green Leaves - Email: [email protected] - Since: March 2nd, 00:58 - Pods: None - Sessions: - March 2nd, 00:58 - July 8th, 01:05. IP: 203.156.215.154 Description: Personal PodLibCopy the code
  1. Submit the index to the remote repository

According to CocoaPods:

Pod Trunk push [name.podspec]

Pod repo push repo [name.podspec]

If the following error is reported, it is not registered, please refer to step 2:

  • Public libraries to submit
pod trunk push PodLogger.podspec --verbose --allow-warnings
Copy the code
  • Private libraries to submit
pod repo push PodLogger PodLogger.podspec --verbose --allow-warnings
Copy the code

Here I use the “public library” submission, submission results are as follows:

We can check it out in CocoaPods/Specs, which is indexed:

4.4 update the local POD repO

If you use pod Search directly at this point, you will not find your library:

$ pod search PodLogger
Copy the code

Although we submitted to the Pod Trunk (pod Specs) successfully, we didn’t have them locally, so we need to update the local POD repository first:

$ pod repo update Updating spec repo `master` $ /usr/local/bin/git -C /Users/chris/.cocoapods/repos/master fetch origin --progress remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (9/9), done. remote: Total 9 (delta 5), reused 0 (delta 0), pack-reused 0 From https://github.com/CocoaPods/Specs ab416c347b51.. 3bd397424c41 master -> origin/master $ /usr/local/bin/git -C /Users/chris/.cocoapods/repos/master rev-parse --abbrev-ref  HEAD master $ /usr/local/bin/git -C /Users/chris/.cocoapods/repos/master reset --hard origin/master HEAD is now at 3bd397424C41 [Add] AudioLibrary 0.7 Updating spec repo 'trunk'Copy the code

If the following path is available on the local PC:

~/.cocoapods/repos
Copy the code

Json index (search_index.json) :

~/Library/Caches/CocoaPods
Copy the code

Delete the index file, and then execute search as follows (…. is prompted to create the index When finished, there is) :

$ pod search PodLogger Creating search index for spec repo 'master'.. Done! -> PodLogger (1.0.0) A pod library demo pod 'PodLogger', '~> 1.0.0' - Homepage: https://github.com/qingye/PodLogger - the Source: https://github.com/qingye/PodLogger.git - Versions: 1.0.0 [master repo]Copy the code

4.5. Modify the main project

# Uncomment the next line to define a global platform for your project platform :ios, '10.0' target 'PodDemo' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! The latest version is used by default, 1.0.0 pod 'PodLogger' endCopy the code

Then pod install –verbose

$POD install --verbose Analyzing Dependencies Downloading Dependencies Installing PodLogger (1.0.0) Generating Pods project Integrating client project Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.Copy the code

Recompile and run the project with the following result:

Note: When we introduce our pod library, it will no longer be placed under “Development Pods”, but under “Pods”!

So far, all the knowledge about CocoaPods has been shared here, although there are many other tips, but these are the main ones!