Skip to main content

How to create your cocoapods?

Lets write our cocoapod and publish it to cocoapods.org

 

 iOS Developer level : Intermediate

 

Configuration when this article was written

 

Xcode : Version 11.5

MacOS : 10.15.5 (Catalina)

 

A working example

 

Final code can be found in the Resources section below.  

 





What is a cocoapod ?


        CocoaPods is an application level dependency manager for the Objective-CSwift and any other languages that run on the Objective-C runtime, such as RubyMotion, that provides a standard format for managing external libraries.

          CocoaPods focuses on source-based distribution of third party code and automatic integration into Xcode projects.


Enough of introduction , let’s be technical…

So to start let us create a framework using xcode.  

Xcode -> New -> Project -> Framework

 

Name It as TTDeviceIdentifier

 

Inside create a file called DeviceIdentifier

 

Add following code

 

import UIKit

 

public struct DeviceIdentifier {

   

    public static func getDeviceUID() -> String {

        if let deviceId = UIDevice.current.identifierForVendor?.uuidString {

            return deviceId

        }

        return ""

    }

}

 

Build once

 

Next

 

Create a repo in github TTDeviceIdentifier

 

Add Readme and Lisence (Select MIT or anything appropriate, I chose MIT)

 

Now  in Terminal cd /Users/………/MY_Frameworks/cocoapods_learning

 

git clone https://github.com/TeaTalkInternal/TTDeviceIdentifier.git

 

again cd to TTDeviceIdentifier

 

ls

 

you will see Readme and Lisence files

 

Now Copy the TTDeviceIdentifier framework you created into current folder (/Users/………/MY_Frameworks/cocoapods_learning/TTDeviceIdentifier)

 

In Terminal now

 

git add .

 

git commit -m "Added TTDeviceIdentifier framework"

 

git push origin master

 

git tag 1.0.0

 

git push --tags

 

Verify in browser if code is available https://github.com/TeaTalkInternal/TTDeviceIdentifier.git

 

 

Now Again Cd TTDeviceIdentifier (do ls -al to see TTDeviceIdentifier.xcodeproj there)

 

pod init 

 

pod spec create TTDeviceIdentifier

 

ls -al

 

you see this

 

-rw-r--r--  1 kevin.saldanha  1645257511   252 Aug 11 16:30 Podfile

drwxr-xr-x@ 5 kevin.saldanha  1645257511   160 Aug 11 16:23 TTDeviceIdentifier

-rw-r--r--  1 kevin.saldanha  1645257511  6321 Aug 11 16:49 TTDeviceIdentifier.podspec

drwxr-xr-x@ 5 kevin.saldanha  1645257511   160 Aug 11 16:19 TTDeviceIdentifier.xcodeproj

 

open -a xcode TTDeviceIdentifier.podspec

 

Modify to look like below

 

Pod::Spec.new do |spec|

 

 

  spec.name         = "TTDeviceIdentifier"

  spec.version      = "1.0.0"

  spec.summary      = "Cocoapod for managing network calls in swift."

  spec.description  = "A Cocoapod for managing network calls in swift."

  spec.license       = "MIT"

  spec.homepage     = "https://github.com/TeaTalkInternal/TTDeviceIdentifier/"

  spec.author             = { "Kevin Vishal" => "vishalkevin11@gmail.com" }

  spec.social_media_url   = "https://twitter.com/vishalkevin11"

  spec.swift_version = '5.0'

  spec.platform     = :ios, "12.0"

  spec.source       = { :git => "https://github.com/TeaTalkInternal/TTDeviceIdentifier.git", :tag => "1.0.0" }

  spec.source_files  = "TTDeviceIdentifier/**/*.{h,m,swift}"

 

end

 

 

pod spec lint

 

You should get something like this

 

 -> TTDeviceIdentifier (1.0.0)

    - NOTE  | xcodebuild:  note: Using new build system

    - NOTE  | xcodebuild:  note: Building targets in parallel

    - NOTE  | [iOS] xcodebuild:  note: Planning build

    - NOTE  | [iOS] xcodebuild:  note: Constructing build description

    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

 

Analyzed 1 podspec.

 

TTDeviceIdentifier.podspec passed validation.

 

Now our pod is actually ready . we can Test by adding an example project. This example project can be shipped into repo

 

 

So now create a simple viewcontroller base application using xcode and save your project here

 

Xcode -> New -> Project -> Single View App

 

Name it Example

 

And Save here

(/Users/………/MY_Frameworks/cocoapods_learning/TTDeviceIdentifier)

 

Now cd Example

 

pod init

 

open -a xcode Podfile

 

add below line after   # Pods for Example

 

pod "TTDeviceIdentifier", :path => "../TTDeviceIdentifier"

 

 

Now in terminal ‘pod install

 

 

open -a xcode Example.xcworkspace

 

In ViewController.swift added the following in viewDidLoad()

 

print(DeviceIdentifier.getDeviceUID())

 

and add import TTDeviceIdentifier at top.

 

So your ViewController looks like this

 

import UIKit

import TTDeviceIdentifier

 

class ViewController: UIViewController {

 

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view.

        print(DeviceIdentifier.getDeviceUID())

    }

}

 

Run the project you should see UUID in xcode console

 

cd ..

git add .  

git commit -m "Ädded Sample Project"

git push origin master

 

 

cd TTDeviceIdentifier

 

ls

 

Podfile

TTDeviceIdentifier.podspec

TTDeviceIdentifier                

TTDeviceIdentifier.xcodeproj

 

pod trunk register ke*****in@gmail.com 'Kevin Vishal' --description='macbook pro'

 

you will be asked to complete your registration

 

 

pod trunk push

 

 

you should get this

 

🎉  Congrats

 

 🚀  TTDeviceIdentifier (1.0.0) successfully published

 📅  August 11th, 17:48

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

 👍  Tell your friends!

 

 

 

Now your pod is up

 

You can create a xcode project

 

Xcode -> New -> Project -> Single View App

 

Name it SampleApp

 

Save it in Desktop

 

In terminal

 

cd to the project folder cd ˜/Desktop/SampleApp

 

pod init

 

open -a xcode Podfile

 

add below line after   # Pods for SampleApp

 

pod 'TTDeviceIdentifier', '~> 1.0'

 

Now in terminal ‘pod install’

 

You have the pod installed

 

open -a xcode SampleApp.xcworkspace

 

We stop here ...

 

Resources:

 

  https://cocoapods.org/pods/TTDeviceIdentifier


https://github.com/TeaTalkInternal/TTDeviceIdentifier/

 

My Reference :  

 

https://www.youtube.com/watch?v=oZSZ8mievUU

 

https://en.wikipedia.org/wiki/CocoaPods#:~:text=CocoaPods%20is%20an%20application%20level,format%20for%20managing%20external%20libraries.&text=CocoaPods%20is%20strongly%20inspired%20by,Ruby%20projects%20RubyGems%20and%20Bundler.

 

 

Comments

Popular posts from this blog

iTunes (Apple App Store) release Pre-Requisites

 iTunes (Apple App Store) release Pre-Requisites  This is small note on details to be kept ready before you release you app ( .ipa file ) to apple app store. Following details you need to have in-hand before releasing app to Apple App Store.   Name of the App Privacy Policy URL  Promotional Text  Keywords (This will make you app more available when customers search on app store) Description Support URL Keywords  Marketing URL Copyright App Store Icon( 1024 px X 1024 px ) App Screenshots (Minimum 3),Sizes are mentioned below. (Please ask this with your UI Designer)     For Review Process   Test  Account Credentials  (This is for Apple to run through the app) 1.      Email  2.      Password     Contact Information    The person in your organisation who should be contacted if the App Review team has any questions or needs additional information.   1.      First Name 2.      Last Name 3.      Email 4.      Phone Number App Screenshots Sizes   iPhone screenshot sizes: iPhone 3 (3.5 Inch): 9

Helper Sites to build your Mobile App

Helper Sites to build your Mobile App ( Primary Stuff ) Idea to App   Following are the links , supporting your journey in transforming an idea into an app   Wireframes Have the screens you want  your  app to a have drawn on paper. Then have the photos of each screen clicked individually , Then use POP  https://marvelapp.com/pop/   . This  app helps you have your wireframes connected, just like an mock app.   Color Theme To decide on the color for your apps use   https://colorhunt.co/   https://www.materialpalette.com/ Visual Design To refer already existing designs use  https://pttrns.com/  , To design VD use  https://www.uxpin.com/   Free icons  (Free for commercial use) https://www.flaticon.com/ https://icons8.com/ https://www.iconfinder.com/free_icons Background Images   use   http://www.resplashed.com/     App Icons   To create app icons use  https://makeappicon.com/   App Store Screen Shots  https://theapplaunchpad.com   http://sketchtoappstore.com/   App Landing Page   To create