directory

1. Create a remote repository on Github

2. Create a local component code base

3. Submit the components to the Github repository

4. Publish components to CocoaPods

5. Import project components

6. Common mistakes


1. Create a remote repository on Github

  • 1. Go to the Github page and click The New button

  • 2. Create a repository

  • 3. You have obtained the URL of the warehouse

  • 4. Use git command or Sourcetree to clone the url to a local directory and you can use Github to manage the related code

2. Create a local component code base

1. Install cocoapods

If you don’t have cocoapods installed, install cocoapods first

Create a POD account:

To publish components to Cocoapods, you need to have apod account. You can use the pod trunk me command to view your account information. If you do not have apod account, you need to register it.

Pod Trunk Register Mailbox name

Example:Once the registration is complete, you can check the pod Trunk Me again to see if it is successful

3. Create a local component code base
  • Create command:

Pod lib create < component name >

  • Example (it is better for the terminal to enable proxy, otherwise it is easy to report errors) :

pod lib create LLComponentDemon

  • The execution results will ask some questions:

What is your email? What platform do you want to use? [iOS/macOS] What language do you want to use? [Swift/ObjC] Would you like to include a demo application with your library? [Yes/No] Whether to automatically generate a template library to do demo testing frameworks will you use? [Quick/None] Would you like to do view based testing? [Yes/No] Whether to perform view-based tests

  • Example (select one based on your actual requirements) :

What is your email?

What platform do you want to use?? [ iOS / macOS ]

  • iOS

What language do you want to use?? [ Swift / ObjC ]

  • Swift

Would you like to include a demo application with your library? [ Yes / No ]

  • Yes

Which testing frameworks will you use? [ Quick / None ]

  • None

Would you like to do view based testing? [ Yes / No ]

  • No

When the above steps are complete, you get a project file that looks like this:

Project Contents:

Example project file directory:


4. Project Components Add component code
  • The added component code is placed in the LLComponentDemon -> Classes folder

  • Add file, add a LLTest component file, replaceme. swift file can be deleted

  • Add the added component file Pod to the Example folder

1. Go to the Example folder (Podfile folder)

2. Run pod install

  • Once executed, the project directory will see the component files in the Pods

Note: Component classes and related external methods need to be usedpublicDeclaration, or external calls will not report an error

If the LLtest class is not decorated with public, the external class cannot be called:

Now that our local component code base is complete, we can import the component code locally using pod Install.


3. Submit the components to the Github repository

1. Modify the. Podspecs index file. Open the llComponentdemon. podSpec file in the project

Pod::Spec.new do |s|
  s.name             = 'LLComponentDemon'  #1.Component name S.Sion ='0.0.1' #2.Version number, which is the same as the tag value'This is a Demon' #3.Component description #4.Description S.description = << -desc TODO: Addlong description of the pod here.
                       DESC
                       
  s.homepage         = 'https://github.com/lanlinxl/LLComponentDemon' #5.Component home page s.license = {:type =>'MIT', :file => 'LICENSE' } #7.Component usage protocol S.thor = {'lanolin'= >'[email protected]' } #8.The author #9.Github remote repository index s.ource = {:git =>'https://github.com/lanlinxl/LLComponentDemon.git', :tag => s.version.to_s }  
  
  s.ios.deployment_target = '9.0' #10.The lowest supported version s.source_files ='LLComponentDemon/Classes/**/*' #11.Component file path s.wift_version ='5.0' #12.Version # s.dependency supported by Swift'AFNetworking'.'~ > 2.3' #13.Component dependent library EndCopy the code

The above file must be changed:

  • The third part is not changed, and the backstage press conference is warned

  • Step 5 May generate the default address, not your Github repository address

  • The generated index at 9 May also be the default index, not your Github remote repository index

  • If a component is dependent on another component, you need to release this comment and reference the component, and you need to add the dependent component to your Podfile to ensure that the project will compile.

  • To learn more about podSpec Settings, see the PodSpec common syntax and subdirectories

2. To submit the github repository to the LLComponentDemon root directory, run the following command:

Git add. Git commit -m “commit” git remote add origin The version number must be the same as that in your podSpec, otherwise you will get an error verifying the cocoaPods index file

  • Example:

Git add. Git commit -m “1.0.0 “git remote add origin github.com/lanlinxl/LL Git push origin master git tag 1.0.0 git push

  • Git remote add origin.. The following error is reported when you go to the same warehouse

error: remote origin already exists.

You need to call git remote rm Origin

4. Publish components to CocoaPods

1. Verify that the cocoaPods index file CD is stored in the LLComponentDemon root directory

pod spec lint –verbose –allow-warnings

  • Verify successful print:

  • Verification failed:

Check that the version number in your podSpec file matches the git tag version number listed above

2. The publishing component is executed in the component project root with the. Podspec file, which is also the LLComponentDemon root

The command is as follows:

pod trunk push xxxx.podspec

Example:

pod trunk push LLComponentDemon.podspec

If warnings are configured, add –allow-warnings to the end

pod trunk push TShareView.podspec –allow-warnings

Now that the component is complete, we can use pod Trunk Me to check whether it has been successfully published, or we can go to the Cocopods website to search the component directly (it will take a few minutes if there is a cache).

5. Import project components

1. CD to the directory where the project has the Podfile file. 2

3. The terminal runs the commandpod install

4. Components used in the project:

Done ~


Common mistakes

  1. Git push origin master error

git push error: failed to push some refs to … We need to pull any files from the remote code base into the local code base before we can push the new code into the Github code base.

Git pull –rebase origin master

2. If our component contains the OC framework header file, the header file may not be found: Find Build Settings -> User Header Search Paths add $(PODS_ROOT) and set to recursive


  • This is the end of componentization for the time being. If there is any mistake, please correct the Demon address