Making a CocoaPod from an existing Xcode project Making a CocoaPod from an existing Xcode project ios ios

Making a CocoaPod from an existing Xcode project


Taken from the Cocoapods documentation:

$ pod spec create YourProject$ edit YourProject.podspec

Then in editor replace s.source_files = "Classes", "Classes/**/*.{h,m}" with

s.source_files = "Classes/**/*.{swift}"

Then run until you pass all tests..

$ pod spec lint YourProject.podspec

Thats basically all.

You can test this Podspec in real life by creating a new demo app and follow the 9 steps from Anbu.Karthik.

In the created podfile add something like:

pod 'YourProject', :path => '/Users/you/work/YourProject'

The path should point to the dir containing the podspec file. Run pod install again.


Easy steps to create Cocoapod from existing xcode project

  • Create a repository on your git account (Repo name, check README,choose MIT under license).
  • Copy the url of your repository.Open terminal and run following command.

    git clone copied your repository url

  • Now copy your Xcode project inside the cloned repository folder onyour Mac. Now run following commands

    git add -u to add all files (if not added use: git add filepath/folder)

    git commit -m "your custom message"

    git push origin master

  • Create a new release to go to your git repository or run following commands

    git tag 1.0.0

    git push --tags

  • First, we need to make sure that you have CocoaPods installed andready to use in your Terminal. run the following command:

    sudo gem install cocoapods --pre

Creating a Podspec 

  • All Pods have a podspec file. A podspec, as its name suggests,defines the specifications of the Pod! Now let’s make one, runfollowing command on terminal

    touch PodName.podspec

  • After adding and modifying your .podspec file. Validate your .podspecfile by hitting following command on terminal

    pod lib lint

  • Once you validate it successfully without errors run followingcommand to register you and build cocoapod respectively

    pod trunk register  

    pod trunk push PodName.podspec

If all goes well, you will get this on terminal

🚀 PodName (1.0.0) successfully published

📅 February 5th, 02:32

🌎 https://cocoapods.org/pods/PodName

👍 Tell your friends!

Yeah!!!!! congrats you have got your pod link. Use wherever you want to use it.