Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Making a CocoaPod - Swift Mumbai #5

Making a CocoaPod - Swift Mumbai #5

CocoaPods is a great tool to help with dependency management when building iOS apps. Having been around and well supported for years, CocoaPods's maturity is evident. While it's very common to use CocoaPods, it's less common to actually create a pod for others to use. This tutorial will walk you through creating your first pod and it will give you some tips on what characterises a great pod.

Bhavesh Sarwar is a Senior iOS Engineer at Mumbai based startup Inspeero Technologies. He loves to adopt new technologies and playing with it. He is adept with Objective C, Swift, React-Native & has a good hand in PHP & JavaScript as well.
https://www.linkedin.com/in/bhavesh-sarwar-882726117/

Presented at Swift Mumbai - Chapter #5 Meetup: https://www.meetup.com/Swift-Mumbai/events/252627724/

Eeb061c8b2816b771920da1b3e7904a3?s=128

Swift India

August 04, 2018
Tweet

Transcript

  1. Making a CocoaPod Bhavesh Sarwar

  2. Roadmap: • What is CocoaPods? • Why CocoaPods? • Create

    your own Public/Private CocoaPod Framework • Using create pod Framework locally • Publish Cocoapods • Use Created pod in project
  3. Before Cocoapods? • Working on a Large scale project •

    Copying source code of third party libraries in to the project • Configure the project with third party libraries • You star the projects repositories on Github to keep track of updates. • Update the source code in your project on updates
  4. What is CocoaPods ? CocoaPods is a dependency manager for

    Swift and Objective-C Cocoa projects. It has over 50 thousand libraries and is used in over 3 million apps. CocoaPods can help you scale your projects elegantly. 
 
 But, what is a dependency manager? And why do you even need one?
  5. Advantages of cocoaPods • improves discoverability of open source libraries

    • Quicker , easier and . . .less risky • Internal dependencies • Semantic versioning • Easy updates Many more . . .
  6. Steps create Custom cocoapods Preliminary steps: • Basic requirements •

    Create Git repo With MIT license & readme • Clone to the local system • Create cocoatouch touch framework in cloned repo • Push working code to git with appropriate version tag
  7. Adding license

  8. • Create pod file • Create pod spec file “pod

    spec create <framework name>” • Edit podspec with appropriate information
  9. Pod::Spec.new do |s| s.name = "ICFrameWork" s.version = "0.1.0" s.summary

    = "Testing pod demo" s.description = <<-DESC This would be the demo to test the custom pod creation DESC s.homepage = "https://git2.inspeero.com/bsarwar/ICFramework" s.license = "MIT" s.author = { "Bhavesh Sarwar" => "bsarwar@inspeero.com" } s.swift_version = "3.2" s.source = { :git => "<Git repo cloning Url>", :tag => "#{s.version}" } s.source_files = "ICFramework/**/* " s.ios.deployment_target = "10.0" end
  10. Optional Values can be used in podspec • s.exclude_files •

    s.public_header_files • s.resource • s.resources = "Resources/*.png" • s.dependency "JSONKit", "~> 1.4" • s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } • # s.requires_arc = true Many more . . .
  11. What is Lint project ? CocoaPods needs to verify that

    nothing is wrong with a project. This spans from limitations and requirements to errors and even suspicious code. How to lint the project ? Linting a project is extremely easy, but could be incredibly annoying! To lint your project run the following in your project directory: pod lib lint cocoaPods required you to lint your project
  12. Test created pod with local dependancy • If you succeed

    to validate your created podspec you can check created pod in local system by local dependencies
 • To do this you need to create new Project a
 Create pod file for this project by “ pod init”
 Add pod into the podfile followed by path
 
 pod <podname> , :path=> “../<path >”
 • Install Pod to the project and check by using the pod
  13. Publishing your Pod You need to publish pod through a

    trunk session
 
 Trunk is web service which allows you to publish pod
 
 You need to create trunk session: 

  14. How to create trunk session pod trunk register <Your Email>


    
 You should quickly get an email from CocoaPods to verify your ‘session’. Verify your account by clicking the link provided in the email. CocoaPods will greet you with friendly message: ACE, YOU ARE SET UP!
  15. Pushing Your Pod All that is left is to push

    your podspec using Trunk to CocoaPods: 
 pod trunk push 
 From the directory where podspec is present
 
 After this you can use pod by pod install 
 
 Live Demo
  16. Private Pods If you want to create pod as private

    you can create repo on github
 
 So only those member can access this pod others will get the access rights error
  17. Thank You Email : bhavesh7sarwar@gmail.com Contact no : 8655555258