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

CocoaPods 2015 talk

CocoaPods 2015 talk

Talk about the current state of CocoaPods, best practices and some of its internals. Given at iOSDevCampDC 2015.

9d2ea021919ff81e02d48530aae191bd?s=128

Boris Bügling

September 04, 2015
Tweet

Transcript

  1. CocoaPods ! iOSDevCampDC, September 2015 Boris Bügling - @NeoNacho

  2. CocoaPods

  3. Contentful

  4. Agenda • What's new and upcoming • CocoaPods plugins •

    How does CocoaPods even • Troubleshooting and Tips
  5. What's new and upcoming

  6. CocoaPods 0.38

  7. support for watchOS Pod::Spec.new do |s| # … s.watchos.deployment_target =

    '2.0' end
  8. Target Deduplication Happens by default, exceptions: • They are used

    on different platforms. • They are used with differents sets of subspecs. • They have any dependency which needs to be duplicated.
  9. Breaking Change to the Hooks- API post_install do |installer_or_rep| #

    @note: Remove after CocoaPods 0.38+ is completely rolled out # and rename block argument to `installer`. installer = installer_or_rep.respond_to?(:installer) ? installer_or_rep.installer : installer_or_rep # You can use the installer from now on. end
  10. Split of xcconfig • pod_target_xcconfig • user_target_xcconfig

  11. Other changes • Removal of the Enviroment Header • Deterministic

    UUIDs by Xcodeproj • Resolver takes the Deployment Target into account
  12. Make sure you check out blog.cocoapods.org and the CHANGELOG for

    major releases
  13. CocoaPods 0.39 • currently beta 4 • Vendored dynamic frameworks

    ! • --private option for linting (ignore warnings only suitable for trunk) • HEADER_SEARCH_PATHS is no longer constructed recursively
  14. Road to 1.0

  15. Major Changes Customizable Installation

  16. Customizable Installation • --no-integrate • Same default • Pass options

    to the installer
  17. Major Changes Target Inheritance

  18. Target Inheritance • :exclusive => true • New options •

    Complete • Search paths • None
  19. Target Inheritance • Allows test targets to work • Allows

    for more 'logical' Podfiles
  20. Coming this fall Hopefully

  21. CocoaPods plugins

  22. CocoaPods plugins • Add subcommands to pod, the tool •

    post_install hook • Each plugin is a Gem
  23. Do whatever you want, because Ruby !

  24. Useful plugins

  25. $ pod plugins list

  26. $ pod keys set AccessToken 0xFFFFFFFF

  27. $ pod package ContentfulDeliveryAPI.podspec

  28. $ pod lib coverage

  29. $ pod roulette

  30. How to build your own plugin

  31. $ pod plugins create cocoapods-awesome-plugin

  32. $ tree . ├── Gemfile ├── LICENSE.txt ├── README.md ├──

    Rakefile ├── cocoapods_awesome_plugin.gemspec └── lib ├── cocoapods_awesome_plugin.rb ├── cocoapods_plugin.rb └── pod └── command └── plugin.rb 3 directories, 8 files
  33. module Pod class Command class Plugin < Command self.summary =

    "Short description." self.arguments = [CLAide::Argument.new('NAME', true)] def initialize(argv) @name = argv.shift_argument super end def validate! super help! "A Pod name is required." unless @name end def run UI.puts "Add your implementation here" end
  34. Hooks

  35. Pod::HooksManager.register(:post_install) do |options| require 'installer' UI.puts "This gets executed after

    installation" end
  36. How does CocoaPods even

  37. use_frameworks!

  38. Build Phases

  39. Check Pods Manifest.lock diff "${PODS_ROOT}/../Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null if [[

    $? != 0 ]] ; then cat << EOM error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation. EOM exit 1 fi
  40. Link Binary With Libraries • Links the aggregate framework •

    Gets build via implicit dependencies
  41. Radar 22392501 Actual Results: It doesn't. You receive this error

    when archiving: [...] So, because they have the same product name, they're overriding each other. How are we supposed to use our own frameworks from our different target types?
  42. Embed Pods Frameworks • Copies the frameworks to the application

    bundle
  43. Copy Pods Resources • Copies resources to the application bundle

  44. Troubleshooting

  45. Mixing Objective-C and Swift in a Pod • Frameworks can't

    have a separate bridging header • Objective-C headers can be included in the umbrella header
  46. First solution: module imports import ObjectiveCPod => You get the

    full public API
  47. Second solution: publiclize all the things • Create a header

    • Import all the Objective-C headers you need • Add that header to public_header_files => Exposes the dependency in the public API
  48. Third solution: custom module map • Module maps can have

    private submodules framework module ResearchKit { umbrella header "ResearchKit.h" module Private { umbrella header "ResearchKit_Private.h" export * } export * module * { export * } } • Can be declared in the podspec with module_map
  49. Reset your integration $ gem install cocoapods-deintegrate $ pod deintegrate

    $ pod install
  50. rm -rf $HOME/ Library/Developer/ Xcode/DerivedData

  51. Filing issues • Read our contribution guidelines • Try if

    your problem reproduces in a separate project • Give us that project! => Help us help you
  52. It gets really old creating countless projects every day :)

  53. Tips

  54. Use bundler to pin your used CocoaPods version $ cat

    Gemfile source 'https://rubygems.org' gem 'cocoapods', '= 0.36.0.beta.1' $ bundle install $ bundle exec pod install # from now on
  55. Make sure your dependencies don't go away • Commit the

    Pods directory • Mirror your Pods (https://github.com/xing/ XNGPodsSynchronizer)
  56. You can keep the Pods history separate • Create an

    orphaned branch on your repo • Check it out as a submodule to Pods • History is now completely separate
  57. Automate your workflow • Use plugins • Use a Rakefile

    or Makefile for common tasks • Use pre_install or post_install hooks in the Podfile
  58. Thank you!

  59. @NeoNacho boris@contentful.com http://buegling.com/talks