Friendship association

1, iOS efficient development – 3 minutes to achieve custom Xcode initialization template

This article mainly explains the Pod library production, release, update process, the specific Pod principle can be searched, in order to facilitate everyone from the beginning can learn to the content, first of all, you can download the Pod library I explain this time: KKPodTest, download and combine to see, efficiency is better, creation is not easy, welcome everyone big brother Star my Demo in GitHub, your random action, is also my creation motivation, thank you!!

This article will update the pit and new technology in the process of using my Pod library. Welcome to pay attention to it!!

To use the CocoaPods management library, you should have a CocoaPods account:

1. Check if you have CocoaPods:

pod trunk me
Copy the code

If the following figure appears, you need to sign up for a CocoaPods membership

Sign up for CocoaPods:

pod trunk register [email protected] 'gavin' <! Click "pod Trunk Me" to check if all registered successfully -->Copy the code

Create a Pod component project

Open terminal, index in Pod inventory position, here is on the desktop, name KKPodTest for example:

1. Go to the desktop folder and execute:pod lib create KKPodTestCreate a Pod component projectThe implications of the question are clear:

  1. Supported Platforms
  2. Supported languages
  3. Whether the Demo application is included (for later test library functions)
  4. Whether to use a testing framework
  5. Whether to use UI tests
  6. The Class prefix

Can also be selected according to the needs, specific can see when the document

4. Project source code analysis

If the Pod library is created successfully, it will open automatically

This is the initialization structure, paying attention to the following:

  1. Kkpodtest. podSpec is the configuration file that we edit and eventually submit to Cocoapods and Git; We can specify the Git source for testing, or private use, also to the Git source
  2. Example for KKPodTest is where we write the Demo test functionality
  3. Pod/KKPodTest/** Here are the classes and image resources that you need to implement.
  4. Note that the version number is the same as the kkpodTest. podSpec compatible version; otherwise, the test may be normal but the actual use may be incorrect
  5. The compatible version number in the Podfile must be the same as the Pod library version number, otherwise the demo will fail to execute Pod Install.

Create Git repository

  • Note:

Git is a third-party tool that you can use to manipulate Git. In Sourcetree, terminal operation is recommended, because the underlying function of Sourcetree is also command. If you do not know the corresponding command of each function in Sourcetree and directly use Sourcetree operation, error may occur. If you are not familiar with terminal command, You can view the status displayed in Sourcetree to evaluate whether the command is correct. During the evaluation, you should also pay attention to whether the status in Sourcetree is delayed. You can restart Sourcetree to determine whether the status is delayed.

  1. Create a repository in Git that KKPodTest is not initialized with (if you don’t have a Git account or can’t create a repository, find your own method)
  2. You need to add a tag to your podspec file to get Git version control.
$git commit -m 'Initial KKPodTest '$git remote add Origin https://github.com/GavinKangDeveloper/KKPodTest.git (your own remote warehouse address) for project tag / / $git tag - m 'First Release' '0.0.1' $git push --tagsCopy the code

6. Edit the podSpec configuration file

  • Default configuration file contents for new project:

  • Configuration file explanation:
S.name = "XXXX" # library name s.sion = "0.0.1" # version number, when the private library needs to update just change this value s.summay = "XXXX" # library introduction, From epage = "https://xxxx" # pod Search should be displayed on the page above. {:type => 'MIT', :file => 'LICENSE'} # open source LICENSE file = {:type => 'MIT'; You can open the LICENSE file to view S.thor = {"name" => "[email protected]"} # author name, email s.ios.deployment_target = '9.0' # Lowest system version supported by the library S.s ource = {: git = > "https://github.com/GavinKangDeveloper/KKPodTest.git", "tag = >" # {s.v ersion} "} # address resources, Pod Install will use this address to download the library you want, and the version you want to download must be the same as S. Sion. Podspec = "Classes/*"; podspec = "Classes/*"; Classes/**/*.{h,m} includes all Classes/**/*.{h,m} includes all Classes/**/*. S.equires_arc = true # Arc supported >>>>> The following is an optional description <<<<< S.resource_bundles = {'KKPodTest' => ['KKPodTest/Assets/*.xcassets']} # s.dependency "JSONKit", #s.public_header_files = "" # public header file, if not public, Users use may not lead time in response to the header file s.s ubspec 'subFolder' do. | | ss ss source_files = 'Classes/XXX / * * / *. {h, m}' ss. Public_header_files = {h}" end # Classes/ XXX /**/*.{h}" Classes/ XXX /**/*.{h}" end # Classes/ XXX /**/*. You can separate each subspec into a subfolder, but be sure to expose.h files through ss.public_header_files, otherwise you may not find the final file.Copy the code
  • Kkpodtest. podSpec configuration content
Pod: : Spec. New do | s | s.n ame = 'KKPodTest' s.v ersion = '0.0.1' s.s ummary = '. A test of Pod 'spyware doctor escription = < < - DESC Mainly to test creation pod library DESC Sheldon horowitz omepage = 'https://github.com/GavinKangDeveloper/KKPodTest' s.l icense = {: type = > 'MIT, :file => 'LICENSE' } s.author = { 'KangKang' => '[email protected]' } s.source = { :git => 'https://github.com/GavinKangDeveloper/KKPodTest.git', : tag = > s.v ersion. To_s} s.s ocial_media_url = 'https://juejin.cn/user/1433418895468397' s.i OS. Deployment_target = '9.0' s.requires_arc = true s.resource_bundles = { 'KKPodTest' => ['KKPodTest/Assets/*.xcassets'] } s.subspec 'UIKit' do |ss| ss.source_files = 'KKPodTest/Classes/UIKit/*.{h,m}' end s.subspec 'Category' do |ss| ss.source_files = 'KKPodTest/Classes/Category/*.{h,m}' end endCopy the code
  • Details on resource_bundles and source_files

  1. Add Files, add Classes and Assets under KKPodTest
  2. Delete the gitkeep and replaceme. m files under Classes and Assets
  3. New folder, Xcassets, classification
  • ‘*’ indicates that all files are matched
  • ‘*.{h,m}’ matches all files ending in. H and. M
  • ‘**’ matches all subdirectories
  • The path is relative to the kkpodTest. podspec file. If it is the same as kkpodTest. podspec, write the folder name directly, otherwise write the corresponding file

7. Verify the configuration file

Enter in the pod library path:

Pod Lib Lint or POD Spec LintCopy the code
  • Source code compiled by Pod Lib Lint comes from the podspec directory rather than the git address specified by source
  • Pod Spec Lint will be networked to get the source code from the git address and verify that the version tag is present on the git address

You can use pod lib Lint to verify that it is correct, and then upload it to Git, but ultimately use the source code. If pod repo push or pod Trunk push fails, You can also use pod Spec Lint to verify that there is a problem and compare the configuration files in Git with those in the local repository.

There are warnings, but no errors. This is usually because of the incorrect path of resource_bundles and source_files

Add podSpec to local

Submitting a PodSpec to the Spec Repo does two things:

  1. Podspec must be validated
  2. Delete unnecessary comments
  • Local initialization component repository, after initialization can be in their own computer~/.cocoapods/repos/Directory below open view
pod repo add KKPodTest https://github.com/GavinKangDeveloper/KKPodTest.git
Copy the code
  • Add to the local repository, if you do not want to see the warning, you can add--allow-warningsKKPodTest is followed by the path to your podSpec
pod repo push KKPodTest ~/Desktop/KKPodTest/KKPodTest.podspec  --allow-warnings
Copy the code

Upload your Podspecs and modifications to Git

$git commit -m 'Initial KKPodTest '$git commit -m 'Initial KKPodTest pushCopy the code

Git push –set-upstream origin master git push — upstream origin master git push — upstream origin master

Test whether Git repository is available locally

Create a project that integrates Cocoapods into the KKPodTest library. Add the index address to the KKPodTest library.

  • Podfile contents:
Platform :ios, "9.0"chua Target 'KKTest' do pod 'SDWebImage','4.4.7' pod 'KKPodTest' :git => 'https://github.com/GavinKangDeveloper/KKPodTest.git' endCopy the code

If pod install fails, you can annotate the KKPodTest created by pod update and unannotate pod install.

  • Effect after successful execution:

11. Submit the PodSpec locally

  • Initialize the build warehouse locally
pod repo add KKPodTest https://github.com/GavinKangDeveloper/KKPodTest.git
Copy the code
  • Adding components to the repository can be done in the~/.cocoapods/repos/Under the view
pod repo push KKPodTest ~/Desktop/KKPodTest/KKPodTest.podspec
Copy the code

12. Submit open source components to Pod

Before pushing to pod, it is best to delete the podspec that was just added to the local pod. You can view the effect of the deletion in ~/.cocoapods/repos/ on your computer

$ pod repo remove KKPodTest
Copy the code

Submit podSpec to pod and ignore warnings (upload will not succeed if warnings are not ignored)

$ pod trunk push KKPodTest.podspec --allow-warnings
Copy the code

After the command is executed successfully, the following information is displayed

13. Use after successful submission

After the submission is successful, it can be used like SDWebImage. When using POD Search, if the search cannot be found, you can use the following command to clear the cache and try again. If the search still cannot be found, you can search on pod’s official website

~/Library/Caches/CocoaPods/search_index.json

Copy the code

14. Upgrade the Pod version

The above problem, the following upgrade version is relatively simple, there are mainly the following steps:

Note: check whether the content you add is in the corresponding physical folder.

  1. The upgrade content is modified
  2. Modify the version number in the PodSpec
  3. Push all changes to Git
  4. taggingGit tag tag values
  5. Push the labelgit push --tags
  6. Pushed to the podpod trunk push --allow-warnings

After the push succeeds, you can change the version in the project you are using or update it directly.

Errors encountered and solutions

The NAME.podspec specification does not validate

Solution:

Xcode > Preferences > Locations Specifies the Xcode version of the Command Line Tools.

did not match any file

pod trunk push file patterns: The `resource_bundles` pattern for `KKPodTest` did not match any file
Copy the code

If podSpec pod lib Lint works but pod repo push fails, it could be a path error or an incorrect path in the PODSpec s.ource.

pattern did not match any file.

[iOS] file patterns: The `source_files` pattern did not match any file.
Copy the code

This is a common problem with podSpec pod lib Lint. Note that the configuration in your PodSpec is correct. The path is relative to the kkpodTest. podspec file. If it is the same as kkpodTest. podspec, write the name of the folder directly, otherwise write the path to the corresponding file.

Check whether there are files in the corresponding folder. If there are no files, create a file. The folder must be empty.

If the configuration file verification succeeds in the local path but fails in Git, you may have a cache problem. You can modify a tag and re-verify and submit the file.

Error pushing new version

The following error occurred while executing the POD Trunk push

[!]  There was an error pushing a new version to trunk: Failed to open TCP connection to trunk.cocoapods.org:443 (getaddrinfo: nodename nor servname provided, or not known)Copy the code

This is likely to be a network problem, push a few times, change the network is OK.

To be continued, this article will be based on their own use, long-term update pit and new technology, welcome you to pay attention to!