Seed your own CocoaPod

Seed your own CocoaPod

Do you have an awesome application and would you like to bring its architecture to the next level?

Join me in this talk where I’ll share my experiences and lessons learned from working on CocoaPods. You will learn why making Pods is important for your application’s maintainability and how factoring out code with them, even for internal use, might be what you are looking for.

Talk was given at the Pragma Conference 2013 on the 26th October 2013.

B6dde1a78e6215a592768c1e78a54adc?s=128

Fabio Pelosin

October 26, 2013
Tweet

Transcript

  1. Seed Your O wn CocoaPod Fabio Pelosin @fabiopelosin / irrationalfab

  2. None
  3. CocoaPods manages library dependencies for your Xcode projects.

  4. Ultimately the goal is to improve discoverability of, and engagement

    in, third party open-source libraries by creating a more centralized ecosystem.
  5. Pod additions per day 750 1500 2250 3000 0 200

    400 600 800
  6. Pod additions per day 750 1500 2250 3000 0 200

    400 600 800 R² 0,9993
  7. 2669 Pods Almost 8 Pods per day in the last

    month
  8. 2,2 Years 270.000 Gem Downloads 4.000 Pull Requests 7.300 Podspecs

    1.706 Contributors 16.000 Commits
  9. 16.000 Commits ! Assuming 3 minutes per commit this is

    equivalent to 2.000 hours More than 5 years!
  10. More than 10 projects

  11. None
  12. None
  13. None
  14. None
  15. None
  16. 1706 contributors

  17. None
  18. None
  19. None
  20. Getting started with CocoaPods

  21. $ [sudo] gem install cocoapods $ pod --version Installing CocoaPods

  22. Use `sudo` during the installation only if strictly needed.

  23. Never use `sudo` while launching the `pod` executable!

  24. Simplified installation which doesn’t require the Xcode command line tools

    anymore.
  25. $ cd project_dir $ pod init # Close the project

    # Add least one dependency to your Podfile $ pod install # Check that CocoaPods doesn’t print any warning # Open the workspace # Check that your integrated target builds Integrating a target
  26. target 'Marshmallow' do pod 'AFNetworking', '~> 2.0' pod 'ObjectiveSugar', '~>

    0.5' end The Podfile
  27. Use the optimistic `~>` operator.

  28. Treat your Pods as external frameworks and namespace the imports.

    E.g. `#import <AFNetworking/AFNetworking.h>`
  29. Migration to CocoaPods • Can be performed incrementally. • You

    can install each new dependency and then check that the system works until you have enough confidence. • Should be pretty straightforward if a Pod is available for your libraries.
  30. $ git clone https://github.com/AFNetworking/AFNetworking.git $ edit Podfile # pod 'AFNetworking',

    :path => '~/code/AFNetworking' $ pod install The Path option
  31. Never edit a Pod which doesn’t uses the path option.

  32. Contribute back to libraries!

  33. Seeding your own Pod

  34. $ pod lib create MyAwesomePod $ cd MyAwesomePod # Create

    the project # Copy or create your classes # Configure MyAwesomePod.podspec # Integrate it with CocoaPods $ edit Podfile # pod 'MyAwesomePod', :path => '~/code/MyAwesomePod' $ pod install Creating a new Pod
  35. 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' => 'tonymillion@gmail.com' s.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.' 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 A specification
  36. $ pod spec lint MyAwesomePod/MyAwesomePod.podspec Linting $ cd MyAwesomePod $

    pod lib lint
  37. Use`$ pod lib lint`.

  38. Use Semantic Versioning 2.0.0 for your libraries.

  39. Document your Pod

  40. $ pod push master MyAwesomePod/MyAwesomePod.podspec Pushing to the master repo

  41. Release an open source Pod without a proper license.

  42. Reasons to use CocoaPods even for private libraries

  43. View of the application as the glue layer Encapsulations of

    unit tests
  44. Better encapsulation of code Reusability Dependencies

  45. Paves out the way for open source publication (which in

    some cases makes sense)
  46. Convenience Leaner development with the creation of Demo targets Clear

    identification of which version of a library/source code is used
  47. $ pod repo add MYPrivateRepo SOURCE_URL $ pod push MYPrivateRepo

    MyAwesomePod/MyAwesomePod.podspec Private repos
  48. irrationalfab @fabiopelosin

  49. How CocoaPods works

  50. Pod source files Pods target User Target xcconfig

  51. CocoaPods main tasks • Creates the workspace. • Creates the

    Pods project. • Adds the relative Pod target to your library link in the binaries build phase. • Configures your library with the xcconfigs. • Does some other minor house keeping.
  52. None