/ cocoapod

# Publishing your own CocoaPod Spec

A few days ago, I introduced CocoaPods. Now, if you wish to contribute to this community because, as a developer, you can offer some useful code that you think, would be useful to the community, then here is the way to do this.

I was introducing it with this article CocoaPods - Dream Tool for iOS Developers.

Ok, now let's go and make your project or framework part of the game {% emoji astonished %}

## Prerequisites

I'm assuming there that the framework or the control you'd like to share is hosted on GitHub, so that everything will be hugely simpler.

We'll use for the example, one of mine. It's a framework I made by the time.

# Clone the project hosted on GitHub to your local repository
$git clone git@github.com:Vaseltior/OMGFramework.git  If you read the documentation on how to create your own PodSpec you saw that they are two ways to achieve it : • The first one consists in creating a ticket on the GitHub repository of CocoaPods and directly uploading your repository with the ticket creation. • The second one consists in forking the git@github.com:CocoaPods/Specs.git repository, adding your sources on it and finally asking for a pull request. In my opinion, the second method is better since, the job that the team will have to do is simpler that the first one. ### Forking the pod specs repository (method 2) So we're choosing the simplest method to create your own pod spec here. Forking a GitHub repository. So you'll have to add the original repository as the upstream git you'll be using to fetch down updates when needed. $ git clone git@github.com:Vaseltior/Specs.git
# Clone "CocoaPods/Specs" repository to one of your local directory.
$cd Specs # Changes the active directory in the prompt to the newly cloned "CocoaPods/Specs" directory$ git remote add upstream git@github.com:CocoaPods/Specs.git
# Assigns the original repo to a remote called "upstream"


### Creating the PodSpec

$pod spec create OMGFramework$ edit OMGFramework.podspec
$pod spec lint OMGFramework.podspec  You can find additional information on how to configure your .podspec file here https://github.com/CocoaPods/CocoaPods/wiki/A-pod-specification But here is the edited version of mine : Pod::Spec.new do |s| s.name = "OMGFramework" s.version = "0.0.1" s.summary = "OMGFramework is a set of convenience classes and tools that are commonly used when developing iOS applications." s.homepage = "https://github.com/Vaseltior/OMGFramework" s.license = 'Apache License, Version 2.0' s.author = { "Samuel Grau" => "samuel.grau@gmail.com" } s.source = { :git => "https://github.com/Vaseltior/OMGFramework.git", :tag => "0.0.1" } s.platform = :ios, '5.0' s.ios.deployment_target = '5.0' s.source_files = 'OMGFramework', 'OMGFramework/**/*.{h,m}' end  Once your .podspec file is fully completed with your own values, you have to validate it with a lint to ensure the package is correct for submission. Of course they are many chances you can't pass the validation with the first attempt, and you'll get errors like that one {%emoji unamused %} : $ pod spec lint OMGFramework.podspec

-> OMGFramework (0.0.1)
- ERROR | XCODEBUILD >  OMGFramework/OMGFramework/src/additions/NSArray/NSArray+OMG.m:13:1: error: expected function body after function declarator
- WARN  | The summary is not meaningful
- WARN  | Comments must be deleted
- WARN  | Unable to find a license file
- NOTE  | XCODEBUILD >  OMGFramework/OMGFramework/src/application/version/OMVersionNumber.m:59:5: warning: implicit declaration of function 'OMReleaseSafely' is invalid in C99 [-Wimplicit-function-declaration]
- NOTE  | XCODEBUILD >  OMGFramework/OMGFramework/OMGFramework.m:11:17: warning: cannot find interface declaration for 'OMGFramework'
- NOTE  | XCODEBUILD >  OMGFramework/OMGFramework/OMGFramework.m:11:17: warning: class 'OMGFramework' defined without specifying a base class [-Wobjc-root-class]
- NOTE  | XCODEBUILD >  OMGFramework/OMGFramework/OMGFramework.m:11:29: note: add a super class to fix this problem
- NOTE  | XCODEBUILD >  OMGFramework/OMGFramework/src/core-data/controller/OMCoreDataController.m:77:5: warning: implicit declaration of function 'OMReleaseSafely' is invalid in C99 [-Wimplicit-function-declaration]

Analyzed 1 podspec.

[!] The spec did not pass validation.


But once, you've corrected all the errors and warnings from your project, you should be able to get this kind of successful result message :

\$ pod spec lint ../Specs/OMGFramework

-> OMGFramework (0.0.1)

Analyzed 1 podspec.

OMGFramework.podspec passed validation.


Now, all you have to do is, send a pull request and you're done. You'll soon be able to use your own framework as a cocoa pod. Enjoy!