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

Introduction to Cocoapods

Introduction to Cocoapods

What are Cocoapods, why use them, how to use them internally.

Pawel Dudek

April 26, 2014
Tweet

More Decks by Pawel Dudek

Other Decks in Programming

Transcript

  1. Cocoapods
    Pawel Dudek
    1

    View Slide

  2. How can we manage
    dependencies in
    Cocoa?
    2

    View Slide

  3. 3
    Copy &
    Paste
    Submodules

    View Slide

  4. Copy & Paste
    1.Copy & Paste files

    2.Add other linker flags

    3.Add ARC flags

    4.Add frameworks

    5.Add any other missing build settings

    6.Add resources

    7.Finally, use the component
    4

    View Slide

  5. Copy & Paste Issues
    5
    • Issues with duplicate
    symbols
    • Really hard to manage
    versions

    • Missing other linker flags
    and build settings

    • Missing resources

    View Slide

  6. Submodules
    • Issues with duplicate symbols
    • Somewhat easier to manage versions (if
    they’re properly tagged)

    • Other linker flags

    • And other build settings

    • Resources
    6

    View Slide

  7. Submodules
    1.Add submodule (and check it out)

    2.Add source to project

    3.Add ARC flags

    4.Add frameworks

    5.Add other linker flags

    6.Add any other missing build settings

    7.Fix duplicate symbols

    8.Add resources

    9.Finally, use the component
    7

    View Slide

  8. This is all wrong.
    8

    View Slide

  9. We are to create things.
    9

    View Slide

  10. This is all just wasting
    our time.
    10

    View Slide

  11. Enter Cocoapods
    11

    View Slide

  12. Cocoapods goals
    12
    • Make working with dependencies simple.

    • Improve library discoverability and
    engagement by providing an ecosystem that
    facilitates this.

    View Slide

  13. Cocoapods advantages
    • Automatically handle source code and
    static libraries

    • Automatically handle ARC

    • Automatically handle frameworks

    • Automatically handle builds settings

    • Automatically handle resources
    13

    View Slide

  14. Cocoapods advantages
    The responsibility for configuration requirements lie
    with the creator of component, not you.
    14

    View Slide

  15. How can I install them?
    15
    gem install cocoapods

    View Slide

  16. Basics
    16

    View Slide

  17. How do Cocoapods
    work?
    • Pod - single definition of a component

    • Podfile - list of dependencies

    • Dependencies use semantic versioning

    • Resolving dependencies lists all your
    dependencies and their dependencies

    • Dependencies definitions are a Github
    repository
    17
    ..

    eg 1.2.5

    View Slide

  18. What happens when I
    install pods?
    • Resolve dependencies from Podfile

    • Take an .xcodeproj as a start

    • Generate .xcconfing files and attaches them
    to your project

    • Generate another .xcoproject with static
    library from defined dependencies
    18

    View Slide

  19. What happens when I
    install pods?
    • Generate an .xcworkspace with your
    project and generated .xcodeproject

    • Add a dependency on the generated
    project results to your targets

    • Lock used versions in Podfile.lock
    19

    View Slide

  20. Basic commands
    20
    Installing pods
    pod update
    pod install
    Updating pods

    View Slide

  21. pod install
    • When there is no Podfile.lock - will use
    latest version or version defined in Podfile

    • When there is a Podfile.lock - will use
    version from Podfile.lock or version
    defined in Podfile
    21

    View Slide

  22. pod update
    • Ignored Podfile.lock

    • Will work as ‘pod install’ without a
    Podfile.lock
    22

    View Slide

  23. Podfile
    • Defines platform

    • Defines project (optional)

    • Defines dependencies

    • Defines specific version

    • Multiple targets

    View Slide

  24. Podfile example
    24

    View Slide

  25. platform :ios, '5.0'
    xcodeproj 'TwitterUserTimeline'
    !
    pod 'STTwitter'
    pod 'Mantle', '1.2'
    !
    target :cedar do
    link_with 'TwitterUserTimelineSpecs'
    pod 'Cedar'
    end
    Podfile
    iOS Version

    View Slide

  26. platform :ios, '5.0'
    xcodeproj 'TwitterUserTimeline'
    !
    pod 'STTwitter'
    pod 'Mantle', '1.2'
    !
    target :cedar do
    link_with 'TwitterUserTimelineSpecs'
    pod 'Cedar'
    end
    Podfile
    Project

    View Slide

  27. platform :ios, '5.0'
    xcodeproj 'TwitterUserTimeline'
    !
    pod 'STTwitter'
    pod 'Mantle', '1.2'
    !
    target :cedar do
    link_with 'TwitterUserTimelineSpecs'
    pod 'Cedar'
    end
    Podfile
    Dependencies

    View Slide

  28. platform :ios, '5.0'
    xcodeproj 'TwitterUserTimeline'
    !
    pod 'STTwitter'
    pod 'Mantle', '1.2'
    !
    target :cedar do
    link_with 'TwitterUserTimelineSpecs'
    pod 'Cedar'
    end
    Podfile
    Exclusive target

    View Slide

  29. platform :ios, '5.0'
    xcodeproj 'TwitterUserTimeline'
    !
    pod 'STTwitter'
    pod 'Mantle', '1.2'
    !
    target :cedar do
    link_with 'TwitterUserTimelineSpecs'
    pod 'Cedar'
    end
    Podfile
    Exclusive target name

    View Slide

  30. platform :ios, '5.0'
    xcodeproj 'TwitterUserTimeline'
    !
    pod 'STTwitter'
    pod 'Mantle', '1.2'
    !
    target :cedar do
    link_with 'TwitterUserTimelineSpecs'
    pod 'Cedar'
    end
    Podfile
    Exclusive pod

    View Slide

  31. Cleaning up
    31
    By wiping whole Cocoapods caches
    rm -rf Pods/
    rm -rf ~/Library/Caches/CocoaPods/
    Git/
    rm -rf ~/Library/Caches/CocoaPods/
    GitHub/
    rm -rf ~/.cocoapods/

    View Slide

  32. Moving patch version
    Will automatically update to new available
    patch version
    32
    pod 'Mantle', '~> 1.2.0'

    View Slide

  33. Fun stuff
    33

    View Slide

  34. Using Cocoapods
    for in-house
    components
    34

    View Slide

  35. What you’ll need
    35
    • Cocoapods installed

    • Git repo for specs definitions

    • And you’re all set!

    View Slide

  36. Your own Cocoapods
    Pod spec
    36

    View Slide

  37. Example
    37

    View Slide

  38. Things you’ll have to do
    first
    • Add your own specs repo to local
    cocoapods repo list

    • Push the podspec to your repository
    38

    View Slide

  39. Adding custom specs
    repo
    39
    pod repo add

    View Slide

  40. Pushing to Cocoapods
    specs repo
    40
    pod push

    View Slide

  41. Demo
    41

    View Slide

  42. Resources & Contact
    @eldudi
    github.com/paweldudek
    [email protected]
    Code Examples
    Contact
    42

    View Slide