Mobile Development 10 min read

Create and Publish Your Own CocoaPods Library with Swift

This step‑by‑step guide shows how to set up a GitHub repository, add the required source, podspec, demo, README and LICENSE files, validate the pod, push the code, and finally submit the podspec to the official CocoaPods Specs so others can use your Swift library.

Aotu Lab
Aotu Lab
Aotu Lab
Create and Publish Your Own CocoaPods Library with Swift

1. Create a GitHub repository

CocoaPods libraries are hosted on GitHub, so start by creating a new public repository named O2View . Fill in the repository name, optional description, choose Public (or a private plan if needed), and enable a README, .gitignore and an MIT license.

2. Clone the repository locally

Open a terminal, navigate to the desired folder and run:

cd ~
git clone https://github.com/marklin2012/O2View.git

After cloning, you will see a structure containing LICENSE and README.md (the hidden .git folder holds the version history).

3. Add the files required for a Pods library

3.1 Main class file

Create the Swift source file O2View.swift inside an O2View folder. Example implementation:

import UIKit

public class O2View: UIView {
    public override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.redColor()
    }
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

3.2 .podspec file

Generate a podspec named O2View.podspec with the command: pod spec create O2View Then edit the generated Ruby file, keeping only the essential fields:

Pod::Spec.new do |s|
  s.name         = "O2View"
  s.version      = "0.0.1"
  s.summary      = "Just testing"
  s.description  = <<-DESC
    Private Pods testing
    * Markdown format
  DESC
  s.homepage     = "http://aoto.io/"
  s.license      = "MIT"
  s.author       = { "linyi31" => "[email protected]" }
  s.source       = { :git => "https://github.com/marklin2012/O2View.git" }
  s.platform     = :ios, "9.0"
  s.requires_arc = true
  s.source_files = "O2View/*.swift"
  s.frameworks   = ['UIKit', 'QuartzCore', 'Foundation']
  s.module_name  = 'O2View'
end

3.3 Demo project

Create a demo Xcode project (e.g., O2ViewDemo) that imports and uses O2View to illustrate how the pod works.

3.4 README.md

Write a markdown README that explains the purpose of the library, installation instructions, and usage examples.

3.5 LICENSE

Include an MIT license file, as required by CocoaPods validation.

4. Validate and push the pod

Run the lint command to check the podspec: pod lib lint If you see warnings such as “Git sources should specify a tag”, you can ignore them during development: pod lib lint --allow-warnings A successful run prints “O2View passed validation.”

Commit the new files and push them to GitHub:

git add -A && git commit -m "add pod files"
git push origin master

5. Publish the podspec to CocoaPods Specs

To make the library discoverable via pod search, submit the .podspec to the official CocoaPods Specs repository. This typically involves forking the Specs repo, adding your podspec, creating a pull request, and waiting for the maintainers to merge it.

After the podspec is merged, anyone can add pod 'O2View' to their Podfile and use the library.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CocoaPodsSwiftGitHubPod Development
Aotu Lab
Written by

Aotu Lab

Aotu Lab, founded in October 2015, is a front-end engineering team serving multi-platform products. The articles in this public account are intended to share and discuss technology, reflecting only the personal views of Aotu Lab members and not the official stance of JD.com Technology.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.