I’ve been trying to encapsulate myselfAXUIElementThis MacOS API library is uploaded to Cocoapod for everyone to use under the idea. Build a library from Cocoapod.The address of the library

However, in the process of creation also encountered many problems, but also solved many problems. I’d like to share some with you.

1. Have a repository to store your code first. There are many options for warehouse platforms. Github, Gitlab, Gitee, etc. Based on the largest gay friends platform in the world. So I choseGithubThis platform for gay friends. Then start creating the library:

2. Once the library is created, we need to upload our code files to the library. First we need to clone our new library to local:

CD to the path you need to store the code in the folder! git clone https://github.com/DevilFinger/DFAXUIElement.gitCopy the code

Git git git git git git git git git

3. Create a file namedClasses“, and drag your code into it !!!!!!

4. Now that the basics are in place, we can start building podSpec files. This is an important file that describes your library and allows others to pod into your library!!

pod spec create DFAXUIElement
Copy the code

5. Once created, we can start editing the contents. Can be achieved byvim DFAXUIElement.podspecCompiles and can also be edited through sublime.

Podspec already lists all the rules and explains each rule. But the main ones are as follows:

Pod: : Spec. New do | Spec | Spec. The name = "DFAXUIElement" / / this is the name of your library. Spec version = "1.0.5" / / this is the name of your library Spec. The author = { "Raymondchans" => "[email protected]"}// This is the name of the creator and contact email spec.homepage = "Https://github.com/DevilFinger/DFAXUIElement" / / this is the address of the library spec. The summary = "A fastway to use API in the org.eclipse.swt.accessibility MacOS with AXUIElement with Swift "/ / this is a description of the spec. The source = {: git = >" https://github.com/DevilFinger/DFAXUIElement.git ", License = {:type => "MIT", tag => "#{spec.version}"} Spec. Platform = :osx // This is the platform of the library. Remember! Spec.osx. deployment_target = '10.11' // This is the version of spec.source_files = 'Classes/**/*.{h,m,swift}'// this is the file for your library Spec.public_header_files = 'Classes/*.h'// This is your library's unified header file spec.swift_versions = '4.0' // this is your swift version Spec. pod_target_xcconfig = {'SWIFT_VERSION' => '4.0'} I added end because I saw that other people had it tooCopy the code

6. After we write the PodSpec file, we push the changes and additions to Github

Git add. Git commit -m "init commit" git push git tag '1.0.5Copy the code

7. Make sure everything is ok. We can verify if the PodSpec has any problems

pod spec lint DFAXUIElement.podspec --verbose --allow-warnings
Copy the code

For success, there will be the following tips:

DFAXUIElement.podspec passed validation
Copy the code

8. Push our POD library to Cocoapod. I strongly recommend using Trunk. Don’t ask me why, because that’s what the Google gods do!

pod trunk push DFAXUIElement.podspec --allow-warnings
Copy the code

If you are not already registered, you can use the following command to register

Pod Trunk Register Full name 'user name' --verboseCopy the code

After registering, your email will receive a verification email

9. After the trunk succeeds, the following message is displayed:

About updating the POD library

1. If you need to update the code later, you just need to update the code to Github and push it again:

pod trunk push DFAXUIElement.podspec --allow-warnings
Copy the code

If the latest code cannot be obtained during POD Search or POD Install after the update. You can read mineThe article

As for using libraries, I’m sure most people use them, but I’ll give a brief explanation here.

1. Create a Podfile in your project and type the following:

target 'WindowSnap' do
  use_frameworks!
  
pod 'MASShortcut'
pod 'DFAXUIElement'
end
Copy the code

2. Then import the Module where it needs to be called