Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert an xcode project into a cocoapod?

I have a piece of code that I find I am reusing in multiple different projects so I'd like to make it a cocoapod and use a private cocoapod repo.

My question is How do I setup an xcode project to be a cocoapod? Should it be a static library or an empty 'project' with an appdelegate ok? It seems that you would not want an appdelegate or a main.m in your pod, but it sure makes it easier to run and debug.

Thanks

like image 772
jessehensold Avatar asked Aug 07 '13 15:08

jessehensold


People also ask

What is CocoaPod Xcode?

What is it and what does it do? Cocoapods is an application level dependency manager that runs on objective-c, swift, and any other programming languages that run on Objective-C. It focuses on source-based distribution of third party code and allows automatic integration to your Xcode projects.


1 Answers

A CocoaPod can be as simple as a couple of files. It's all in how you define it in your podspec. You only include the relevant source code files in your podspec (no main.m or anything unless you have a really good reason to do so). My recommendation would be to have a Source directory in the top-level of your repo containing the relevant source files.

If you want to have a demo project to show how to use it, you can do that on the same level, and use the files from the Source directory (don't copy them somewhere under the demo project directory). Having an actual Xcode project is not required to have a pod.

You would probably have something very close the their demo of a very basic podspec:

Pod::Spec.new do |s|
  s.name         = 'Reachability'
  s.version      = '3.1.0'
  s.license      =  :type => 'BSD' 
  s.homepage     = 'https://github.com/tonymillion/Reachability'
  s.authors      =  'Tony Million' => '[email protected]' 
  s.summary      = 'ARC and GCD Compatible Reachability Class for iOS and OS X. Drop in replacement for Apple Reachability.'
  s.source       =  :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' 
  s.source_files = 'Reachability.h,m'
  s.framework    = 'SystemConfiguration'
  s.requires_arc = true
end

Source: http://docs.cocoapods.org/specification.html

And here is the repo for Reachability in this example: https://github.com/tonymillion/Reachability

like image 164
Josh Kovach Avatar answered Oct 25 '22 14:10

Josh Kovach