Mobile Development 12 min read

How to Set Up a Private CocoaPods Spec Repo for iOS Projects

This guide walks you through enabling hidden files on macOS, exploring the .cocoapods directory structure, creating a private spec repository on a Git server, adding it to CocoaPods, writing and validating a podspec, and finally integrating the private pod into an iOS project with version tagging.

Aotu Lab
Aotu Lab
Aotu Lab
How to Set Up a Private CocoaPods Spec Repo for iOS Projects

Enable Hidden Files and Locate .cocoapods

Run the following commands in Terminal to show hidden files in Finder and then restart Finder (Option + right‑click the Finder icon → Relaunch):

defaults write com.apple.finder AppleShowAllFiles -bool true
defaults write com.apple.finder AppleShowAllFiles -bool false

The hidden ~/.cocoapods (or /Users/[username]/.cocoapods) directory contains the repos folder, which holds the spec repositories. Inside repos, the master repo stores the public CocoaPods specs, while the specs folder holds all .podspec files.

Create a Private Spec Repository

On a Git server (GitHub, GitLab, Bitbucket, etc.) create an empty repository to host your private specs. The example uses GitHub and names the repo O2Specs:

Add the repository to CocoaPods locally:

pod repo add O2Specs https://github.com/marklin2012/O2Specs.git

This creates a folder ~/.cocoapods/repos/O2Specs but does not yet contain any specs.

Write a Podspec for Your Private Library

Create a .podspec file for the library you want to distribute. Below is a minimal example for a library called O2View:

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://aotu.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

Validate the podspec locally: pod lib lint If you receive a warning about missing Git tags, you can ignore it during development:

pod lib lint --allow-warnings

Push the Spec to Your Private Repo

After validation, push the spec file to the private repository: pod repo push O2Specs O2View.podspec The command updates the O2Specs repo and shows a successful push output.

Consume the Private Pod in an iOS Project

Create a new Xcode project (e.g., TestPodDemo) and initialize CocoaPods: pod init Edit the generated Podfile to include both the official and private sources, then list the private pod:

source 'https://github.com/CocoaPods/Specs.git'   # official repo
source 'https://github.com/marklin2012/O2Specs.git' # private repo

use_frameworks!

target 'TestPodDemo' do
  pod 'O2View'
end

Install the dependencies: pod install The output confirms that O2View (0.0.1) was fetched from the private repo and integrated successfully.

Publish a Stable Version

When the library is ready for release, tag the Git repository and push the tags:

git tag '0.0.1'
git push --tags
git push origin master

Update the podspec to reference the tag:

s.source = { :git => "https://github.com/marklin2012/O2View.git", :tag => version }

After updating, repeat the pod repo push step to make the tagged version available to consumers.

Summary

By following these steps you can create, host, and consume a private CocoaPods spec repository, enabling you to share internal iOS libraries without exposing them to the public CocoaPods master repo.

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.

CocoaPodsdependency managementpodspecprivate repo
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.