Create your own CocoaPods library

Learn how to create a pod from scratch and utilize Travis and Codecov to make the pod robust.

Introduction

Overview

> pod lib create [pod name]
  1. Set up Xcode project and necessary targets
  2. Link to Github
  3. Implement the pod
  4. Write unit tests
  5. Configure Travis CI and Codecov
  6. Publish the pod
  • macOS Mojave 10.14.3
  • Xcode 10.1
  • Swift 4.2
  • cocoapods 1.6.0

Set up Xcode project and necessary targets

  1. SwiftyLib: Our pod implementation will happen in here
  2. SwiftyLibTests: Unit tests our pod and collects code coverage

Link to Github

> git init
> git remote add origin git@github.com:{USERNAME}/SwiftyLib.git
> git add .
> git commit -m "Initial project setup"
> git push -u origin master
> git pull
...
2 files changed, 24 insertions(+)
create mode 100644 LICENSE
create mode 100644 README.md

Implement the pod

Write unit tests

> git add .
> git commit -m "Added test cases"
> git push

Configure Travis CI and Codecov

> xcodebuild test \
-enableCodeCoverage YES \
-project SwiftyLib.xcodeproj \
-scheme SwiftyLib \
-sdk $TEST_SDK \
-destination "platform=iOS Simulator,OS=$OS,name=$NAME" \
ONLY_ACTIVE_ARCH=YES
> bash <(curl -s https://codecov.io/bash) -t {CODECOV_TOKEN}

Publish the pod

> gem install cocoapods
> pod spec create SwiftyLib
...
Specification created at SwiftyLib.podspec
> pod lib lint
...
-> SwiftyLib (0.0.1)
SwiftyLib passed validation.
> git add .
> git commit -m "Added SwiftyLib.podspec"
> git push
> git tag 0.0.1
> git push origin 0.0.1
> pod trunk push
...
Updating spec repo `master`
---------------------------
🎉 Congrats
🚀 SwiftyLib (0.0.1) successfully published
📅 February 24th, 15:49
🌎 https://cocoapods.org/pods/SwiftyLib
👍 Tell your friends!
---------------------------

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store